如何让MVC运行在iis6.0上 在IIS里面配置MVC项目

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
I’ve seen a lot of reports where people have trouble getting ASP.NET MVC up and running _disibledevent=>Project如何让MVC运行在iis6.0上 在IIS里面配置MVC项目
In the project URL, I gave it a virtual application name of Iis6DemoWeb and then checked Create Virtual Directory. A dialog box should appear and you should now have an IIS virtual application (note this is different than a virtual directory, as indicated by the gear looking icon) under your Default Web Site.
IISProject如何让MVC运行在iis6.0上 在IIS里面配置MVC项目

Using a URL File Extensions

When you run the ASP.NET MVC installer, it will set up an ISAPI mapping in IIS 6 to map the .mvc extension to the aspnet_isapi.dll. This is necessary in order for IIS to hand off requests using the .mvc file extension to ASP.NET.
If you’re planning to use extension-less URLs, you can skip this section, but it may be useful to read anyways as it has some information you’ll need to know when setting up extension-less URLs.

Mapping .mvc to ASP.NET

If you plan to use the .mvc URL extension, and are going to deploy to IIS 6 _disibledevent=>
Make sure you’re _disibledevent=>
In the screenshot, you can see that .mvc is in the list. If it is in the list _disibledevent=>
Now you can copy the path in the Executable text box to your clipboard. This is the path you’ll want to map .mvc to.
Click Cancel to go back to the Application Configuration dialog and then click Add which will bring up an empty Add/Edit Application Extension Mapping dialog.
Fill in the fields with the exact same values as you saw for .aspx, except the extension should be “.mvc” without the quotes. Click OK and you’re done with the mapping.

Specifying Routes with an Extension

Before we run the application, we need to update the default routes to look for the file extension we chose, whether it be .mvc or .aspx extension. Here is the RegisterRoutes method in my Global.asax.cs file using the .mvc extension. If you want to use the .aspx extension, just replace {controller}.mvc with {controller}.aspx.
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{controller}.mvc/{action}/{id}", new { action = "Index", id = "" } ); routes.MapRoute( "Root", "", new { controller = "Home", action = "Index", id = "" } ); }
Note that because the second route, “Default”, has a literal extension as part of the URL segment, it cannot match a request for the application root. That’s why I have a third route named “Root” which can match requests for the application root.
Now, I can hit CTRL+F5 (or browse my website) and I should see the following home page.
HomeextensionapplicationWebsiteIISProject如何让MVC运行在iis6.0上 在IIS里面配置MVC项目
And about page.
AboutHomeextensionapplicationWebsiteIISProject如何让MVC运行在iis6.0上 在IIS里面配置MVC项目
Notice that the URLs contain the .mvc extension.

Uh oh, Houston! We have a problem

Of course, you’re going to want to be able to navigate to the web root for your project. Notice what happens when you navigate to /Iis6DemoWeb.
RootAboutHomeextensionapplicationWebsiteIISProject如何让MVC运行在iis6.0上 在IIS里面配置MVC项目
This is a bug in the Default.aspx.cs file included with our default template which I discovered as I was writing this walkthrough. We’ll fix it right away, but I can provide the fix here as it’s insanely easy.
Note: If you received a File Not Found error when visiting the root, then you might not have Default.aspx mapped as a default document. Follow these steps to add Default.aspx as a default document.
As I’ve written before, this file is necessary for IIS 6, IIS 7 Classic Mode, and pre SP1 Cassini, but not IIS 7 Integrated. So if you’re using Cassini with Visual Studio 2008 SP1 and deploying to IIS 7 Integrated, you can delete Default.aspx and its sub-files.
In the meanwhile, the fix is to make the following change.
Change:
HttpContext.Current.RewritePath(Request.ApplicationPath);
To
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
If you created your website in the IIS root rather than a virtual application, you would never have noticed this issue. But in the virtual application, the URL to the stylesheet rendered contained the virtual application name, when it shouldn’t. Changing the second argument to false fixes this.

IIS6 Extension-less URLs

Ok, now we’re ready to try this with extension-less URLs using the infamous “Star mapping” or “Tags: 

延伸阅读

最新评论

发表评论