In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
IIS in the use of ASP.NET MVC example analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
In this article, we learn to use ASP.NET MVC and URL Routing in different versions of IIS. We learned about processing strategies for IIS7.0, IIS6.0, and earlier versions of IIS.
The ASP.NET MVC framework relies on URL Routing, and to take full advantage of URL Routing, we need to do some additional configuration of the Web server (IIS).
The * version of IIS is IIS7.0 in Windows2008, and we can also install IIS7.0 on the Vista system (except for the Home Basic version).
IIS7.0 provides two modes of processing requests-the integration mode and the traditional mode. If we use IIS7.0, we don't need to do any configuration, and if we want to use traditional mode, we need to do some extra configuration work.
IIS6.0 is installed in Windows2003, if it is Windows Server 2003, then we can upgrade IIS6.0 to IIS7.0. But if we use IIS 6. 0, we need to do some extra configuration work.
The IIS5.1 version of Windows XP Pro is installed, so we also need to do some additional configuration work on IIS5.1.
* * Windows2000 uses IIS5.0, and we also need to do some additional configuration work on IIS5.0.
Here is our summary of the different versions of IIS:
IIS7.0 (integrated mode)-URL Routing can be used without any configuration.
IIS7.0 (traditional mode)-requires special configuration to use URL Routing.
IIS6.0 or earlier-requires our special configuration to use URL Routing.
I. Integrated mode and traditional mode
IIS7.0 can use two modes to process requests-the integration mode and the traditional mode. The integrated mode provides better and more functionality; the traditional mode is designed to be backward compatible with earlier 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
two。 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 figure.
4. Set up the Application pool.
By default, IIS is configured to support two application pools: DefaultAppPool and Classic .NET AppPool. If set to DefaultAppPool, then our application is running in integrated request processing mode. If you set up the Classic .NET AppPool, then our application runs in the traditional request processing mode.
It is important to note that we modify the request processing mode by changing the relationship between the program pool and the application by clicking the "Select" button in the Edit Application dialog box. However, there are several compatibility issues that need to be addressed when ASP.NET applications migrate from traditional mode to integrated 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, then we can use the URL Routing feature without any configuration. But if the ASP.NET program is configured as Classic .NET AppPool, move on.
Second, use ASP.NET MVC in the old version of IIS
If we are using a lower IIS version number than IIS7.0 or using IIS7.0 traditional mode, we have two options:
1. Modify the routing table and add the file extension. If we change the URL address of / Store/Details to / Store.aspx/Details
2. Create wildcard script map. Wildcard script map enables us to map each request to the ASP.NET framework.
If I can't change the configuration of the server, then we have to use the * way. If we don't want to change the URL address, then we have to use the second way to configure the IIS web server.
Here we discuss two ways to use ASP.NET MVC in older versions of IIS:
(1) add an extension to the routing table.
The easiest way to get URL Routing to run on the old version 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)
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 route our following ULR addresses:
/ Home/Index
/ Product/Details/3
/ Product
Unfortunately, however, older versions of IIS will not pass such requests to the ASP.NET framework, so they will not be routed to the controller. For example, when we request the URL of / Home/Index, we will generate an error page prompt. The figure below is as follows
Older versions of IIS can only send URL requests with specific extensions to the ASP.NET framework. For example, / SomePage.aspx requests are mapped to the ASP.NET framework, while / SomePage.htm is not mapped to the ASP.NET framework.
Therefore, for URL Routing to work properly, we must modify the default route to include the file extension to map to the ASP.NET framework. The extensions that can be mapped to the ASP.NET framework are .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: remember to recompile our ASP.NET MVC application after modifying the Global.asax file.
In the above code, we made a small but important change, we changed the default route to the following format:
{controller} .aspx / {action} / {id}
Because of this change, ASP.NET MVC application routing can only be mapped in the following form
/ Home.aspx/Index
/ Product.aspx/Details/3
/ Product.aspx
When we have finished modifying the routing table, we also need to make sure that the URL addresses of all hyperconnections in the program have been modified accordingly. In other words, make sure that all hyperlink navigation addresses contain the .aspx extension. If we use the hyperlink generated by the Html.ActionLink () method, we don't need to make changes to the hyperlink.
(2) create Wildcard Script Map
If we do not want to change the URL address in the ASP.NET 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 way. This avoids changing the default routing table.
One thing to be clear is that this change causes IIS to process every request, even a request for an image, an ASP page, a HTML page. So using wildcar script map makes the operation more implicit.
Enable wildcard script map for IIS7.0
1. Select our application in the Connections window
two。 Make sure the Features view is selected.
3. Double-click the Handler Mappings button.
4. Click Add Wildcard Script Map, as shown.
5. Enter the path to the aspnet_isapi.dll file
6. Enter MVC in the Name text box
7. Click the OK button.
To create a wildcar script map in IIS6.0:
1. Right-click the site and select Properties
2. Select "Home Directory" tab
3. Click the "Configuration" button
4. Select the "Mappings" tab
Click the "Insert" button, as shown in the following figure
6. Enter the path where the aspnet_isapi.dll file is located in the Executeable text box
7. Remove the tick before the Verify that file exists check box.
8. Click the OK button
When we have configured wildcard script map, we can use the default routing table to handle the following URL address
/ Home/Index
/ Product/Details/3
/ Product
Summary
In this article, we explained how to use ASP.NET MVC in older versions (or IIS7.0 traditional mode) of IIS. We discussed two ways to solve the problem of URL Routing working with older versions of IIS: modifying the default routing table or creating a wildcard script map
* this method requires us to modify the ASP.NET MVC application. The advantage of this approach is that we do not need to operate the web server, but just modify the routing table in the program.
The second approach requires us to create wildcard script map, which has the advantage that we don't need to modify our code, but the disadvantage is that it affects the performance of the ASP.NET MVC program.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.