8. Use ASP. net mvc in different versions of IIS

Source: Internet
Author: User

in this Article , we learned to use ASP. net mvc and URL routing in different versions of IIS. We will learn how to handle IIS In iis7.0, iis6.0, and earlier versions.
Asp. net MVC framework depends on URL routing. to make full use of URL routing, We need to configure some additional Web Server (IIS.
the latest version of IIS is iis7.0 in windows2008. You can also install iis7.0 In the Vista system (besides the Home Basic version.
iis7.0 provides two request processing modes- integration mode and traditional mode . If iis7.0 is used, no configuration is required. If the traditional mode is used, additional configuration work is required.
iis6.0 is installed in Windows2003. For Windows Server 2003, we can upgrade iis6.0 to iis7.0. However, if we use IIS 6.0, we need to do some additional configuration work.
for iis5.1 installed in Windows XP Professional Edition, we also need to perform some additional configuration work on iis5.1.
Finally, Windows2000 uses iis5.0. We also need to perform some additional configuration work on iis5.0.
below is a summary of different versions of IIS:
iis7.0 (integrated mode)-URL routing can be used without any configuration.
iis7.0 (traditional mode)-Special configuration is required to use URL routing.
iis6.0 or a lower version-we need special configuration to use URL routing.

I. Integration mode and traditional mode(Original: Home of the gray WormHttp://hi.baidu.com/grayworm )
Iis7.0 can process requests in two modes: the integration mode and the traditional mode. The integration mode provides better and more functions. The traditional mode is to be backward compatible with earlier versions of IIS.
The request processing mode is composedProgramDetermined by the pool , You can set the request processing mode of a Web application by specifying the way the application pool is associated with the application. The procedure is as follows:
1. run IIS Service Manager
2. Select an application in the connections window
3. Click Basic settings connection in the actions window to open the edit application dialog box, as shown in.
4. Set the application pool.
By default, IIS is configured to support two application pools:DefaultapppoolAndClassic. Net apppool. If it is set to defaappapppool, our application runs in the integrated request processing mode. If classic. Net apppool is set, our application runs in the traditional request processing mode.
Figure 1
Note that you can click the select button in the edit application dialog box to change the association between the application pool and the application and modify the request processing mode. However, ASP. NET applications need to solve compatibility issues when migrating from the traditional mode to the integration mode. For more information, see the following articles:
Upgrading ASP. NET 1.1 to IIS 7.0 on Windows Vista and Windows Server 2008 -- http://learn.iis.net/page.aspx/270/upgrading-aspnet-11-to-iis7-on-windows-vista--windows-server-2008/
ASP. NET integration with IIS 7.0-http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/
If our ASP. NET application uses defaultapppool, we can use the URL routing function without any configuration. However, if the ASP. Net program is configured as the classic. Net apppool, continue to look down.

 

2. Use ASP. net mvc in earlier versions of IIS(Original: Home of the gray WormHttp://hi.baidu.com/grayworm)
If we use a lower IIS version number than iis7.0 or use the traditional iis7.0 mode, we have two options:
1. Modify the route table and add the file extension.For example, we change the/store/details URL to/store. aspx/details.
2. Create a wildcard script map.Wildcard script Map allows us to map every request to the ASP. NET Framework.
If I cannot modify the server configuration, we have to adopt the first method. If we do not want to modify the URL address, we must use the second method to configure the IIS web server.

Here we discuss two methods respectively:
(1) Add an extension to the route table.
The easiest way to enable URL routing to run on earlier IIS versions is to open the global. asax file and modify our route table. Route table Code As follows:
Listing 1-Global. asax (unmodified)
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. MVC;
Using system. Web. Routing;
Namespace mvcappcs
{
Public class globalapplication: 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 void application_start ()
{
Registerroutes (routetable. routes );
}
}
}
The default routing configuration can be used to route the following ULR addresses:
/Home/Index
/Product/details/3
/Product
Unfortunately, earlier 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 the URL "/home/Index", an error page is displayed. For example

Figure 2
Earlier versions of IIS can only send URL requests with specific extensions to the ASP. NET Framework. For example, the/somepage. aspx request will be mapped to the ASP. NET Framework, while/somepage.htm will not be mapped to the ASP. NET Framework.
Therefore, to make URL routing work properly, we must modify the default route so that it contains the file extension to be mapped to the ASP. NET Framework. Extensions that can be mapped to ASP. NET frameworks include. aspx. axd and. ashx.
The modified global. asax file is as follows:
Listing 2-Global. asax (modified with extensions)
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. MVC;
Using system. Web. Routing;
Namespace mvcappcs
{
Public class globalapplication: 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 void application_start ()
{
Registerroutes (routetable. routes );
}
}
}
Note: After modifying the global. asax file, remember to recompile our ASP. net mvc application.
In the above Code, we made a small but important modification. We changed the default route to the following format:
{Controller}. aspx/{action}/{ID}
Due to this change, ASP. net mvc application route maps only the following form.
/Home. aspx/Index
/Product. aspx/details/3
/Product. aspx
After modifying the route table, we also need to make sure that all the hyperconnected URL addresses in the program have been modified accordingly. In other words, make sure that all hyperlink navigation addresses contain the. aspx extension. If we use HTML. actionlink () to generate a hyperlink, we do not need to change the hyperlink.

(2) create a wildcard script Map(Original: Home of the gray WormHttp://hi.baidu.com/grayworm)
If we do not want to modify the URL address in the ASP. net mvc application and can access the Web server, we canMap all requests to the ASP. NET Framework by creating a wildcard script map. This avoids modifying the default tables.
It should be clarified that such modification will enable IIS to process each request, even if it requests an image, ASP page, and HTML page. Therefore, using wildcar script map will make the operation more implicit.

Enable the wildcard script map of iis7.0
1. select our application in the connections window
2. confirm that the features view is selected.
3. Double-click handler mappings.
4. Click Add wildcard script map ,.
5. Enter the path of the aspnet_isapi.dll file.
6. Enter MVC in the name text box
7. Click OK.

 

Figure 3

To create a wildcar script map in iis6.0:
1. Right-click the site and select Properties
2. Select the Home Directory tab.
3. Click "configuration ".
4. Select the Mappings tab.
5. Click "insert", as shown in
6. Enter the path of the aspnet_isapi.dll file in the executeable text box.
7. Remove the check box before the verify that file exists check box.
8. Click OK.
Figure 4

After configuring the wildcard script map, we can use the default route table to process the following URL address.
/Home/Index
/Product/details/3
/Product

 

Summary
This article explains how to run the ASP. net mvc program in the earlier version of IIS (or the traditional iis7.0 mode. We have discussed two ways to solve the problem of collaboration between URL routing and earlier versions of IIS: modifying the default route table or creating a wildcard script map.
The first method requires us to modify the ASP. net mvc application. The advantage of this method is that we do not need to operate the web server, but just modify the route table in the program.
The second method requires us to create a wildcard script map. The advantage of this method is that we do not need to modify our code, but the disadvantage is that it will affect the performance of ASP. net mvc.

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