Web site where the MVC schema is run under IIS6 without modifying the IIS settings in the virtual host

Source: Internet
Author: User
Tags httpcontext

The people who read this article must have an MVC base, so I don't explain a lot of nouns.

There are 1 conditions for erecting MVC in older versions of IIS: Framwork 3.5,SP1 must be installed. So if your virtual host is 2.0, then you're free to talk. The market is now generally upgraded to 3.5.


If you don't have the simplest terms, your server will not be able to use the MVC architecture site at all.

Okay, so here's a few steps we're going to take.


1. Copy several missing runtime to bin folder

The main reason for the old version's inability to run is of course because of missing DLL files, the most important of which is the MVC core Library

Top three in C:/Program Files/microsoft asp.net/asp.net MVC 2

System.Web.Mvc.dll

System.Web.Mvc.xml

Microsoft.Web.Mvc.Build.dll

The following 2 are 3.5 SP1 dynamic link library, to have a copy of the SP1 computer can be

System.Web.Routing.dll

System.Web.Abstractions.dll


2. Create a new Default.aspx page in the root directory and write code in the background

The older version of IIS verifies that the file exists, so you must create a new page and then write the code on it.

1 public partial class _default:page
2 {
3 public void Page_Load (object sender, System.EventArgs e)
4 {
5 HttpContext.Current.RewritePath (Request.applicationpath);
6 IHttpHandler HttpHandler = new Mvchttphandler ();
7 httphandler.processrequest (httpcontext.current);
8}
9}
10

3. Set up route routing table

In order to take full advantage of the new features of MVC, it is highly recommended that you use the Controller[/action][/id].aspx form when building your site.

Square brackets represent an omission, but you can't just omit the action without omitting the ID (which can actually be implemented, but with limitations and attention points, I'll introduce the basics here)

The main parameter is the ID, and if you have more than one HTTP parameter, you need to use the display get to transmit

Controller/action/id.aspx?page=1

The following is the route setting in the Global.asax file

Default Match
Routes. Maproute ("Noaction", "{controller}.aspx", new {controller = "Home", action = "index", id = ""}); No action matching
Routes. Maproute ("Noid", "{controller}/{action}.aspx", new {controller = "Home", action = "index", id = ""}); No-ID match
Routes. Maproute ("Default", "{controller}/{action}/{id}.aspx", new {controller = "Home", action = "index", id = ""} ); Default Match
Routes. Maproute ("Root", "", new {controller = "Home", action = "index", id = ""}); Root directory Match

After this configuration, other people visit your website or want to asp.net like before, all are ASPX suffix name.

This will not be a problem for your virtual host after this configuration.

ok,3 your website to virtual space after completing a step. It's not usually a problem.

This site is the MVC architecture, the following to a download address, is the default file and the 5 library files

Note that you change the namespaces in the Default.aspx and Default.aspx.cs files yourself, but you don't change them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.