IIS“礼貌重定向”如何影响ASP。NET MVC或者其他web框架?

时间:2022-07-14 03:34:53

I read in http://support.microsoft.com/kb/298408 that IIS6.0 automatically responds with a "courtesy redirect" (HTTP 301) on URLs that lack a dot.

我在http://support.microsoft.com/kb/298408中看到,IIS6.0在没有点的url上自动响应一个“礼貌重定向”(HTTP 301)。

When a browser requests a URL such as http://www.servername.de/SubDir, the browser is redirected to http://www.servername.de/SubDir/. A trailing slash is included at the end of the URL.

当浏览器请求http://www.servername.de/SubDir等URL时,浏览器将被重定向到http://www.servername.de/SubDir/。URL末尾包含一个尾斜杠。

Internet Information Server (IIS) first treats SubDir as a file that it should give back to the browser. If this file cannot be found, IIS checks to see if there is a directory with this name. If a directory with this name exists, a courtesy redirect with a 302 "Object moved" response message is returned to the browser. This message also contains the information about the new location of the directory with the trailing slash. In turn, the browser starts a new GET request to the URL with the trailing slash.

Internet Information Server (IIS)首先将SubDir视为应该返回给浏览器的文件。如果找不到这个文件,IIS将检查是否有一个同名的目录。如果存在具有此名称的目录,则返回带有302“对象移动”响应消息的礼貌重定向到浏览器。此消息还包含有关目录的新位置的信息,并带有斜杠。反过来,浏览器会启动一个新的GET请求,并使用尾随斜杠来访问URL。

How does this behavior intersect with a framework like ASP.NET MVC, which employs URLs that do not require or use dots, in general?

这种行为是如何与ASP这样的框架相结合的。NET MVC,通常使用不需要或不使用点的url ?

Specifically... does ASP.NET MVC "turn off" this feature of IIS6.0 when installed? If so, how?

特别是……ASP。NET MVC在安装时“关闭”IIS6.0的这个特性?如果是这样,如何?

I would guess that is not the case, but instead the request routing done in IIS sends the request to ASPNET before performing the redirect. If someone could explain, I'd be grateful.

我猜情况并非如此,相反,IIS中完成的请求路由会在执行重定向之前将请求发送到ASPNET。如果有人能解释,我会很感激的。

1 个解决方案

#1


2  

The routing engine in ASP.NET MVC allows you to use extensionless routes in your application. You could configure IIS 6.0 to handle such URLs by making a wildcard mapping which would associate the aspnet_isapi filter with all requests meaning that everything passes through the ASP.NET engine for processing.

ASP中的路由引擎。NET MVC允许您在应用程序中使用无扩展路由。您可以通过创建通配符映射来配置IIS 6.0来处理这些url,通配符映射将aspnet_isapi过滤器与所有请求关联起来,这意味着所有的请求都要经过ASP。净引擎进行处理。

When installed on a server with IIS 6.0 ASP.NET MVC does not do any modifications to the IIS metabase meaning that extensionless routes won't work.

当在服务器上安装IIS 6.0 ASP时。NET MVC不会对IIS metabase做任何修改,这意味着无扩展路由不能工作。

My recommendation would be to use extensionless routing only on IIS 7 and higher and have some extension (like .mvc) for IIS 6.0. This avoids the wildcard mapping and the possible performance hit for having the ASP.NET engine serving even static files like images, css, javascript, ...

我的建议是只在IIS 7或更高版本上使用无扩展路由,并为IIS 6.0提供一些扩展(如.mvc)。这避免了通配符映射和使用ASP可能造成的性能损失。NET引擎甚至服务于静态文件,如图像、css、javascript……

#1


2  

The routing engine in ASP.NET MVC allows you to use extensionless routes in your application. You could configure IIS 6.0 to handle such URLs by making a wildcard mapping which would associate the aspnet_isapi filter with all requests meaning that everything passes through the ASP.NET engine for processing.

ASP中的路由引擎。NET MVC允许您在应用程序中使用无扩展路由。您可以通过创建通配符映射来配置IIS 6.0来处理这些url,通配符映射将aspnet_isapi过滤器与所有请求关联起来,这意味着所有的请求都要经过ASP。净引擎进行处理。

When installed on a server with IIS 6.0 ASP.NET MVC does not do any modifications to the IIS metabase meaning that extensionless routes won't work.

当在服务器上安装IIS 6.0 ASP时。NET MVC不会对IIS metabase做任何修改,这意味着无扩展路由不能工作。

My recommendation would be to use extensionless routing only on IIS 7 and higher and have some extension (like .mvc) for IIS 6.0. This avoids the wildcard mapping and the possible performance hit for having the ASP.NET engine serving even static files like images, css, javascript, ...

我的建议是只在IIS 7或更高版本上使用无扩展路由,并为IIS 6.0提供一些扩展(如.mvc)。这避免了通配符映射和使用ASP可能造成的性能损失。NET引擎甚至服务于静态文件,如图像、css、javascript……