In the VM, the website running the MVC Architecture under IIS6 does not modify the IIS settings.

Source: Internet
Author: User

Why should I write this tutorial?

This is mainly to solve the problem of deploying websites on virtual hosts, because you cannot configure virtual hosts at all.
Therefore, you can run MVC in earlier versions of IIS without configuring IIS.

 

 

First, we recommend two good places to learn MVC:

1, classic MVC video tutorial: http://www.youku.com/playlist_show/id_2416830.html

2, Microsoft official MVC Tutorial: http://www.asp.net/mvc/learn (English,... In this way, I can easily understand all four levels ...)


People who read this article must have an MVC basis, so I will not explain many terms.

In earlier versions of IIS, setting up MVC has one condition: framwork 3.5 must be installed, and SP1 is not required. So if your VM is 2.0, you can leave it alone. Now the market is generally upgraded to 3.5


If you do not have the simplest condition, your server will not be able to use the MVC-based website.

Now, let's take a few steps.


1. Copy several missing runtime libraries to the bin folder.

The main reason why the old version cannot run is the lack of DLL files. The most important thing is the MVC core library.

The first three are 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 two dynamic link libraries of 3.5 SP1 can be copied to a computer with SP1.

System. Web. Routing. dll

System. Web. Export actions. dll


2. Create the default. aspx page in the root directory and write the code in the background.

In earlier versions, IIS verifies whether the file exists. Therefore, you must create a new page and write the code.

 

  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 the route table

To fully utilize the new features of MVC, we strongly recommend that you use the Controller [/action] [/ID]. aspx format during website construction.

Square brackets indicate that actions can be omitted, but actions cannot be omitted rather than IDS (actually, they can be implemented, but there are restrictions and notes. Here I will introduce the basics first)

The primary parameter is the ID. If there are multiple HTTP parameters, it needs to be transmitted with the display get.

Controller/Action/ID. aspx? Page = 1

The following is the route settings in the global. asax file.

 

 // Match by default
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 matching
Routes. maproute ("default", "{controller}/{action}/{ID }. aspx ", new {controller =" home ", Action =" Index ", id =" "}); // default match
Routes. maproute ("root", "", new {controller = "home", Action = "Index", id = ""}); // match the root directory

 

After this configuration, other users still want to access your website like the previous Asp.net, all of which are suffixed with Aspx.

In this way, your VM will not go wrong.

OK. After completing the three steps, release your website to the virtual space! Generally, no problem occurs.

This website uses the MVC Architecture. Here is the default file and the five library files.

Note that you can change the namespace in the default. aspx and default. aspx. CS files without changing the namespace.

(Rayfile)

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.