MVC deployment to

Source: Internet
Author: User
A summary of the experience with mvc in IIS in this article we learned to use mvc and URL Routing in different versions of IIS. We learned about handling policies for IIS7.0, IIS6.0, and earlier versions of IIS.
The MVC framework relies on URL Routing, and to take full advantage of URL Routing, we need to make some extra configuration of the Web server (IIS).
The latest version of IIS is IIS7.0 in Windows2008, and we can also install IIS7.0 in Vista (except Home Basic edition).
IIS7.0 is a model that provides two types of processing requests-integration patterns and traditional patterns. If you use IIS7.0, then we do not need to do any configuration, if we want to use the traditional mode, we need to do some additional configuration work.
IIS6.0 is installed in Windows2003, and if it is Windows Server 2003, then we can upgrade IIS6.0 to IIS7.0. But if we use IIS 6.0, then we need to do some extra configuration work.
The IIS5.1 version of the Windows XP Professional installation, so we also need to do some extra configuration work for IIS5.1.
Finally Windows2000 is using IIS5.0, and we also need to do some extra configuration work for IIS5.0.
Here's a summary of our different versions of IIS:
IIS7.0 (Integrated mode)-you can use URL Routing without any configuration required.
IIS7.0 (Traditional mode)-we need to make a special configuration to use the URL Routing.
IIS6.0 or lower version-we need to make a special configuration to use the URL Routing.
Integration mode and traditional mode
IIS7.0 can use both modes to handle request-integration and traditional patterns. Integration mode provides better and more functionality; traditional mode is for backward compatibility with older versions of IIS.
The processing mode of the request is determined by the program pool, and we can set the request processing mode of the Web application by specifying how the program pool is associated with the application. The steps are as follows:
1. Run IIS Service Manager
2. Select an application in the Connections window
3. Click the basic settings connection in the Actions window to open the Edit Application dialog box, as shown in the following illustration.
4. Set application pool.
By default, IIS is configured to support two types of application pools: DefaultAppPool and Classic. NET AppPool. If set to DefaultAppPool, then our application will run in Integrated request processing mode. If you set Classic. NET AppPool, our application runs in the traditional request processing mode.

Note that we modify the request processing mode by clicking the "Select" button in the Edit Application dialog box to change the association between the program pool and the application. But applications need to address several compatibility issues when migrating from traditional mode to Integrated mode. For more information, see the following articles:
Upgrading 1.1 to IIS 7.0 on Windows Vista and Windows Server 2008--HTTP://LEARN.IIS.NET/PAGE.ASPX/270/UPGRADING-A spnet-11-to-iis7-on-windows-vista--windows-server-2008/ integration with IIS 7.0-
If our application uses DefaultAppPool, we can use the URL routing function without any configuration. But if the program is configured to classic. NET AppPool, keep looking down.
Second, using MVC in older versions of IIS
If we use an IIS version that is lower than IIS7.0 or uses the IIS7.0 traditional mode, then we have two options:
1, modify the routing table, plus the file name extension. If we change the URL address of/store/details to/store.aspx/details
2, create wildcard script map. The wildcard script map allows us to map each request to the framework.
If I can't modify the server configuration, we have to take the first approach and if we don't want to modify the URL, we have to configure the IIS Web server in the second way.
Here we discuss two ways to use mvc in older versions of IIS:
(i) Add an extension to the routing table.
The easiest way to make URL routing run on older versions of IIS is to open the Global.asax file and modify our routing table. The code for the routing table is as follows:
Listing 1–global.asax (unmodified)
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingsystem.web; usingSYSTEM.WEB.MVC; usingSystem.Web.Routing; namespaceMvcappcs { Public classGlobalApplication:System.Web.HttpApplication { Public Static void registerroutes (routecollection routes)                    {                         routes. Ignoreroute ("{resource}.axd/{*pathinfo}");                         routes. Maproute (                               "Default",// route name                                "{controller}/{action}/{id}",// url with  parameters                              New{controller = "Home", action = "Index", id = ""}//Parameter defaults); } protected voidApplication_Start () {registerroutes (routetable.routes); }            }    }
The default routing configuration allows us to route the following ULR addresses:
Unfortunately, older versions of IIS do not pass such requests to the ASP.NET framework, so these requests are not routed to the controller. For example, when we request/home/index this URL, we will produce an error page prompt. The following figure

Older IIS can only send URL requests with specific extensions to the framework. For example, the/somepage.aspx request is mapped to the framework, and/somepage.htm is not mapped to the framework.
Therefore, to make the URL routing work, we have to modify the default route so that it contains the file name extension to map to the framework. The extensions that can be mapped to the framework are. aspx. Axd and. ashx
The modified Global.asax file looks like the following
Listing 2–global.asax (modified with extensions)
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingsystem.web; usingSYSTEM.WEB.MVC; usingSystem.Web.Routing; namespaceMvcappcs { Public classGlobalApplication:System.Web.HttpApplication { Public Static void registerroutes (routecollection routes)                    {                         routes. Ignoreroute ("{resource}.axd/{*pathinfo}");                         routes. Maproute (                               "Default", // route  name                              "{controller}.aspx/{action}/{id}", //  Url with parameters                               New{controller = "Home", action = "Index", id = ""}//Parameter defaults); } protected voidApplication_Start () {registerroutes (routetable.routes); }            }    }
Note: After modifying the Global.asax file, remember to recompile our MVC application.
In the code above, we made a very small but important change, and we modified the default route to the following format:
Because of this change, the MVC application route can only map the following form
After we have modified the routing table, we also want to make sure that all of the hyperlinks in the program URL address are also modified accordingly. In other words, make sure that all the hyperlink navigation addresses contain an. aspx extension. If we use the hyperlink generated by the Html.ActionLink () method, we do not need to make changes to the hyperlink.
(ii) Create wildcard Script Map
If we do not want to modify the URL address in the MVC application and have access to the Web server, we can map all requests to the ASP.NET framework by creating a wildcard script map. This avoids modifying the default by the table.
The point is that this modification will make IIS handle every request, even if it requests a picture, ASP page, HTML page. Therefore, the use of the Wildcar script map makes the operation more implicit.
Wildcard script map with IIS7.0 enabled
1. Select our application in the Connections window
2. Make sure the features view is selected.
3. Double-click the Handler Mappings button.
4. Click Add Wildcard Script map, as shown in figure.
5. Enter the path to the Aspnet_isapi.dll file
6. Enter MVC in the Name text box
7. Click OK button.

To create a Wildcar script map in IIS6.0:
1, right click on the site, select Properties
2. Select the Home Directory tab
3, click the "Configuration" button
4, select the "Mappings" tab
5, click the "Insert" button, as shown in the following figure
6. Enter the path of the Aspnet_isapi.dll file in the executeable text box
7, remove verify that file exists check box before the tick.
8. Click OK button

When we have finished configuring the wildcard script map, we can use the default routing table to process the following URL address
In this article we explain how to use MVC in older versions (or IIS7.0 traditional mode) IIS. We discussed two ways to solve the problem of URL routing working with older IIS: Modifying the default routing table or creating a wildcard script map
The first approach requires us to modify the MVC application, and the advantage of this is that we don't need to manipulate the Web server, but just modify the routing table in the program.
The second approach is that we need to create the wildcard script map, the advantage of which is that we do not need to modify our code, but the disadvantage is that it affects the performance of the MVC program.

Will MVC 2 department on IIS6 and IIS7 tutorials
My Program development environment:
System: Win7
Development tools: VS2008 SP1
MVC version: MVC 2.0 RC

Before deploying an MVC application, make sure that your Program Bin folder contains System.Web.Mvc.dll (very important) below, as shown in the figure:

If not, open the list of references in your MVC project, as shown in the figure:

Right-click SYSTEM.WEB.MVC, select "Properties", go to the following window:

Set Copy Local to True (the default is False), and then build the project, and System.Web.Mvc.dll will appear under the Bin folder.

First talk about the IIS7 environment that is easiest to deploy:
Mine is the Win7 system, where Win7 is integrated with the IIS7 version, it is easy to deploy MVC 2.0 programs on Win7, as long as the site's application pool is set to "integrated".
(In fact, IIS7 below the site, the application is the default integration method, that is, IIS7 above the MVC site, the default support)

After you select the integration method, you can see the configuration entries for "*.mvc" in the "handler mappings" of the functional View:

This allows you to run the MVC program.

Next, talk about the configuration of IIS6 on win 2003:
Build a site on IIS6, and then in the site properties, "Home directory"-"Configuration", will open the following window:

Insert a map in the "Wildcard Application Mappings" below, which the executable file is given. NET "Aspnet_isapi.dll", the default address is generally "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"

To this end, IIS6 's integrated MVC is complete.

Finally, if your project bin below System.Web.Mvc.dll, the above configuration is certainly not successful, if the System.Web.Mvc.dll file is in the project's Bin folder.
[url=] [/URL]

Related Article

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: 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.