Use ASP. net mvc on different versions of IIS

Source: Internet
Author: User
Tags classic asp
ArticleDirectory
    • Integration mode and Classic Mode
    • Use ASP. net mvc in earlier versions of IIS
    • Add extension to route table
    • Create a wildcard script ing
    • Summary

ASP. net mvc framework depends on URL routing. To useURL Routing, You may have to perform additional configuration steps on the Web server. These steps depend on the version and application of Internet Information Services (IIS ).ProgramRequest processing mode.

The latest version of IIS is version 7.0. This version of IIS is included in Windows Server 2008. You can also install IIS 7.0 on any Vista operating system except home basic (see http://technet.microsoft.com/en-us/library/cc732624.aspx ).

IIS 7.0 supports two modes of request processing. You can use the integration mode or classic mode. When using IIS 7.0 in integrated mode, no special configuration steps are required. However, when IIS 7.0 is used in Classic mode, additional configuration is required.

Microsoft Windows Server 2003 contains IIS 6.0. When using Windows Server 2003, you cannot upgrade IIS 6.0 to IIS 7.0. When using IIS 6.0, you must perform other configuration steps.

Microsoft Windows XP Professional includes IIS 5.1. When using IIS 5.1, you must perform other configuration steps.

Finally, Microsoft Windows 2000 and Microsoft Windows 2000 Professional include IIS 5.0. When using IIS 5.0, you must perform other configuration steps.

The following is a summary of different IIS versions:

    • IIS 7.0 (integrated mode)-No special configuration is required to use URL routing.
    • IIS 7.0 (Classic mode)-You must perform special configurations to use URL routing.
    • IIS 6.0 or earlier-you must perform special configurations to use URL routing.
Integration mode and Classic Mode

IIS 7.0 can process requests in two request processing modes: integration mode and classic mode. The integration mode provides better performance and more functions. Classic mode is used to provide backward compatibility to earlier versions of IIS.

The request processing mode is determined by the application pool. By determining the pool associated with the application, you can determine the processing mode used by a specific web application. Perform the following steps:

    1. Start Internet Information Services Manager.
    2. Select an application in the connections window.
    3. In the actions window, clickBasic settingsLink to open the edit application dialog box, as shown in 1.
    4. Pay attention to the selected application pool.

By default, IIS is configured to support two application pools:DefaultapppoolAndClassic. Net apppool.If you selectDefaultapppoolThe application runs in integrated request processing mode. If you selectClassic. Net apppoolThe application runs in the classic request processing mode.

Figure 1: Detect request processing mode (click to view the large image)

Note that you can modify the request processing mode in the edit application dialog box. Click the select button and change the application pool associated with the application. Note that there is a compatibility problem when you change ASP. NET applications from the classic mode to the integration mode. For more information, see the following articles:

    • Upgrade ASP. net 2008 to IIS 1.1 -- http://learn.iis.net/page.aspx/270/upgrading-aspnet-11-to-iis7-on-windows-vista--windows-server-2008/ on Windows Vista and Windows Server 7.0
    • ASP. NET integration with IIS 7.0-http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/

If ASP. NET Applications UseDefaultapppoolThe URL routing (ASP. net mvc) works normally without any additional steps. However, if you configure ASP. NET Applications to useClassic. Net apppool, Please continue to read this tutorial and have more work to do.

Use ASP. net mvc in earlier versions of IIS

If you need to use ASP. net mvc in IIS versions earlier than IIS 7.0, or you need to use IIS 7.0 in Classic mode, there are two options available. First, modify the route table to use the file extension. For example, you can use URL/store. aspx/details instead of URL/store/details.

The second option is to createWildcard script ing. Wildcard script ing can map each request to ASP. NET Framework.

If you do not have access to the Web server (for example, ASP. net mvc applications are hosted by Internet service providers), use the first option. If you do not want to modify the URL content but have the right to access the Web server, you can use the second option.

We will discuss these two options in detail in the following sections.

Add extension to route table

The simplest way to make URL routing work with earlier IIS versions is to modifyGlobal. asaxThe route table in the file. In program list 1Global. asaxFile is configured with a route named default.

Program list 1Global. asax(Not modified)

  1. UsingSystem;
  2. UsingSystem. Collections. Generic;
  3. UsingSystem. LINQ;
  4. UsingSystem. Web;
  5. UsingSystem. Web. MVC;
  6. UsingSystem. Web. Routing;
  7.  
  8. NamespaceMvcappcs
  9. {
  10. Public ClassGlobalapplication: system. Web. httpapplication
  11. {
  12. Public Static VoidRegisterroutes (routecollection routes)
  13. {
  14. Routes. ignoreroute ("{Resource}. axd/{* pathinfo }");
  15. Routes. maproute (
  16. "Default",// Route name
  17. "{Controller}/{action}/{ID }",// URL with Parameters
  18. New{Controller ="Home", Action ="Index", Id =""}
  19. // Parameter defaults
  20. );
  21. }
  22. Protected VoidApplication_start ()
  23. {
  24. Registerroutes (routetable. routes );
  25. }
  26. }
  27. }

The default route configured in program list 1 allows URL transfer as follows:

/Home/Index

/Product/details/3

/Product

Unfortunately, earlier versions of IIS cannot pass these requests to ASP. NET Framework. Therefore, these requests are not sent to the Controller. For example, if a URL/home/INDEX request is sent from a browser, the error page shown in 2 is displayed.

 

Figure 2: The Error 404 Not found is received (click to view the large image)

Earlier versions of IIS only map specific requests to ASP. NET Framework. The request must be a URL with the correct file extension. For example, the/somepage. aspx request maps to ASP. NET Framework. /Somepage.htm requests cannot be mapped.

Therefore, to make URL routing work, we must modify the default route so that it contains the extension that can be mapped to ASP. NET Framework. File extensions that can be mapped to ASP. NET include. aspx,. axd, And. ashx.

TheGlobal. asaxFiles can work with earlier versions of IIS.

Program list 2Global. asax(After the extension is modified)

  1. UsingSystem;
  2. UsingSystem. Collections. Generic;
  3. UsingSystem. LINQ;
  4. UsingSystem. Web;
  5. UsingSystem. Web. MVC;
  6. UsingSystem. Web. Routing;
  7.  
  8. NamespaceMvcappcs
  9. {
  10. Public ClassGlobalapplication: system. Web. httpapplication
  11. {
  12. Public Static VoidRegisterroutes (routecollection routes)
  13. {
  14. Routes. ignoreroute ("{Resource}. axd/{* pathinfo }");
  15. Routes. maproute (
  16. "Default",// Route name
  17. "{Controller}. aspx/{action}/{ID }",// URL with Parameters
  18. New{Controller ="Home", Action ="Index", Id =""}
  19. // Parameter defaults
  20. );
  21. }
  22. Protected VoidApplication_start ()
  23. {
  24. Registerroutes (routetable. routes );
  25. }
  26. }
  27. }

Important:After changing the global. asax file, do not forget to generate the ASP. net mvc application again.

In program list 2, there is only oneGlobal. asaxSmall but important changes to the file. The URL mode of the default route is as follows:

{Controller}. aspx/{action}/{ID}

Adding the. aspx extension is the file type that has changed the URL routing model resolution. With this change, the ASP. net mvc application can now send the following requests:

/Home. aspx/Index

/Product. aspx/details/3

/Product. aspx

After modifying the route table, make sure that all links in the application are compatible with the new URL mode. In other words, make sure that all links contain the. aspx extension. If you useHtml. actionlink ()If the Helper method generates a link, no changes are required.

Create a wildcard script ing

If you do not want to modify the content of the URL used for the ASP. net mvc application, but you have the right to access the Web server, you can use another option. You can create a wildcard ing to map all requests to the Web server of ASP. NET Framework. In this way, you can use the default ASP. net mvc route table on IIS 7.0 (Classic mode) or IIS 6.0.

Note that this option will cause IIS to parse each request sent to the web server. This includes requests for images, classic ASP pages, and HTML pages. Therefore, enabling wildcard script ing to ASP. NET is indeed related to performance issues.

The following describes how to enable wildcard script ing on IIS 7.0:

    1. Select an application in the connections window.
    2. Ensure selectedFeaturesView.
    3. Double-clickHandler MappingsButton.
    4. ClickAdd wildcard script MapLink, as shown in 3.
    5. Enter the path to the aspnet_isapi.dll file (you can copy this path from the pagehandlerfactory script ing ).
    6. Enter the name MVC.
    7. ClickOKButton.

 

Figure 3: Use IIS 7.0 to create a wildcard script ing (click to view the large image)

Follow these steps to create a wildcard script ing using IIS 6.0:

    1. Right-click the website and select Properties.
    2. SelectHome DirectoryTab.
    3. ClickConfigurationButton.
    4. SelectMappingsTab.
    5. ClickInsertButton, as shown in figure 4.
    6. Paste the aspnet_isapi.dll path to the executable field (you can copy this path from the script ing in The. aspx file ).
    7. DeselectVerify that file existsCheck box.
    8. ClickOKButton.

 

Figure 4: Use IIS 6.0 to create a wildcard script ing (click to view the large image)

After you enable wildcard script ing for IIS 7.0 or IIS 6.0, you can make requests work with the following default route table:

/Home/Index

/Product/details/3

/Product

Summary

The purpose of this tutorial is to explain how to use ASP. net mvc while using earlier versions of IIS (or classic-mode IIS 7.0. We have discussed two ways to make URL routing work with earlier versions of IIS: modifying the default route table or creating a wildcard script ing.

The first method requires modifying the URL used in ASP. net mvc applications. The advantage of this method is that you can modify the route table without accessing the web server. This means that this method can be used when an Internet proxy company acts as a proxy for ASP. net mvc applications.

The second method is to create a wildcard script ing. The advantage of this method is that you do not need to modify the URL. The disadvantage of the second method is that it may affect the performance of ASP. net mvc applications.

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.