Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
994 views
in Technique[技术] by (71.8m points)

asp.net - trailing slash issue in IIS 8.5

We are moving a ASP.NET project from IIS6 (Win Server 2003) to IIS 8.5(Win Server 2012 R2). The project has some MVC components for which the following routing is used.

routes.MapRoute("simple", "{controller}.mvc/{action}/{id}");
routes.MapRoute(
                "Default", 
                "{controller}.mvc/{action}/{id}"                            
                new { controller = "Home", action = "Index", id = "" }
            );

Thus call to MyDemoController would be accessed by MyDemo.mvc

Now what happens, when I use the url as MyDemo.mvc/ it works, but when I use MyDemo.mvc without the slash it throws 404 error.

This happens only in the deployed server. In our local machines, which use IIS7.5, Win 7 it works without any issues.

Manually changing is not possible as there are lots of urls added to the sitemap file and our client does not approve the approach.

Is it something specific to the IIS version or any small tweak would solve the issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Take a look at the following. I believe this is your problem. It has to do with the .mvc extension.

ASP.NET MVC - Routing - an action with file extension

Dots in URL causes 404 with ASP.NET mvc and IIS

The problem is that IIS will handle the .mvc file as a static file and will by default not route the hypothetical .mvc file through your MVC application. IIS handles the request and your MVC code never gets a change to route to this file.

In summary, here's what the configuration looks like to make .mvc files work:

<system.webServer>
  <handlers>
    <add name="MVCFileHandler"
      path="*.mvc"
      verb="GET" type="System.Web.Handlers.TransferRequestHandler"
      preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0"  />
  </handlers>
</system.webServer>

As for it working on IIS7.5, Win 7 without any issues and not IIS 8.5.

take a look at this answer

Routing a url with extension in MVC4 won't work, tries to serve up static file

There is also <modules runAllManagedModulesForAllRequests="true"> but it doesn't seem to work for MVC4/IIS8 (used to be ok in MVC3/IIS7 IIRC). More info here. There is also a performance impact with this one as every request will route through the managed pipeline.

Hope all this helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...