简体   繁体   English

Global.asax中的URL重写-IIS7

[英]URL Rewriting in Global.asax - IIS7

I have a fairly detailed problem with which I hope someone can help. 我有一个相当详细的问题,希望有人可以提供帮助。 Basically, I have a .NET 4.0 website hosted on IIS7 that has some pages that necessitate URL rewriting. 基本上,我在IIS7上托管了一个.NET 4.0网站,该网站包含一些必须重写URL的页面。 In order to implement these features, I have added a method to my global.asax that maps the extension-less URLs to their proper ASPX pages, and then performs a context.RewritePath in order to display the correct page. 为了实现这些功能,我在global.asax中添加了一种方法,该方法将无扩展名的URL映射到其正确的ASPX页面,然后执行context.RewritePath以显示正确的页面。

Initially, I called this method from application_BeginRequest. 最初,我从application_BeginRequest调用了此方法。 However, we have some business necessary logging that occurs when Session_Start is called, and it appears that this logging is not always happening since the implementation of the URL rewriting in application_BeginRequest - Basically, every session gets logged in the DB, and after initial deployment of the URL rewriting, our session logs have dropped by about 20%, with no corresponding errors in the application log. 但是,在调用Session_Start时,我们会发生一些业务必需的日志记录,并且由于在application_BeginRequest中重写URL的实现,这种记录似乎并不总是发生-基本上,每个会话都记录在数据库中,并且在初始部署后重写URL后,我们的会话日志减少了约20%,而应用程序日志中没有相应的错误。 At the same time, our IIS logs seem to be showing a relatively unchanged amount of traffic, so to my eyes, it appears that the sessions are not instantiating properly. 同时,我们的IIS日志似乎显示相对不变的流量,因此在我看来,会话似乎未正确实例化。

As a workaround for this issue, I moved the URL rewriting from application_BeginRequest to application_AcquireRequestState, so that this code won't fire until after I'm (mostly) sure that the Session has started. 作为解决此问题的方法,我将URL重写从application_BeginRequest移到了application_AcquireRequestState,这样直到我(主要是)确定Session已启动之后,此代码才会触发。 This works in my local dev environment and on our staging server (Windows Server 2008 - IIS 7 - .NET 4.5 Framework installed). 这在我的本地开发环境和登台服务器(已安装Windows Server 2008-IIS 7-.NET 4.5 Framework)中有效。 In the Production environment (Windows Server 2008 - IIS 7 - .NET 4.5 Framework), I get 404 errors when trying to browse to the extension-less URL to be re-written. 在生产环境(Windows Server 2008-IIS 7-.NET 4.5 Framework)中,尝试浏览到要重写的无扩展名URL时出现404错误。

I'm completely stumped - I've verified that I'm using the Integrated app pool, my web.config has the "runAllManagedModulesForAllRequests=true" attribute, my IIS features include HTTP redirection and static file compression, but nothing appears to be working. 我完全感到困惑-我已验证我正在使用集成应用程序池,我的web.config具有“ runAllManagedModulesForAllRequests = true”属性,我的IIS功能包括HTTP重定向和静态文件压缩,但似乎没有任何作用。 There's a hack that I found for using the Classic app pool, and creating extra script map handlers to handle wildcard URLs with no extensions, but I'm hesitant to put that in place in production. 我发现有一个使用Classic应用程序池的黑客,它创建了额外的脚本映射处理程序来处理不带扩展名的通配符URL,但是我很犹豫将其投入生产。

Any help you can provide would be greatly appreciated. 您能提供的任何帮助将不胜感激。 Thank you! 谢谢!

I would concentrate on why there was a 20% drop in session logs. 我将集中讨论为何会话日志减少20%。 Are you sure there wasn't also a drop in traffic? 您确定流量也没有减少吗? Are you using redirects for people coming to your site using the old .aspx Urls? 您是否对使用旧版.aspx Urls进入网站的用户使用重定向? Perhaps you received more 404 traffic that would not trigger the Session_Start? 也许您收到了更多不会触发Session_Start的404流量? Did Google Analytics confirm that traffic maintained normal levels after the UrlRewite was put into place? UrlRewite启用后,Google Analytics(分析)是否确认流量保持正常水平? You could also use IIS Log Parser to filter out static files and query 200 vs 404s from the log files to get a better sense of actual traffic. 您还可以使用IIS Log Parser过滤出静态文件,并从日志文件中查询200 vs 404,以更好地了解实际流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM