重写 Global.asax、ASP.NET 中的 url
你好。我需要将双斜杠替换为一个斜杠。我计划在 Global.asax Application_BeginRequest 事件中执行此操作。够了吗?或者更好地做一个http模块? 谢谢。
UPD
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo(AppSettings.UsedCulture)
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
Dim retUrl As String
....
some code
....
'Dim app As HttpApplication = CType(sender, HttpApplication)
'app.Context.RewritePath(retUrl)
Dim myContext As HttpContext = HttpContext.Current
'Rewrite the internal path
myContext.RewritePath(retUrl)
End If
我正在使用 .Net 1.1。并且它必须在 .Net 1.1 上 RewritePath 不会重写 URL。为什么?
UPD2 决定在 Sub Application_BeginRequest 中使用新的重写 url 进行附加重定向。
HEllo. I need replace double slashes in one slash. I am planning do this in Global.asax Application_BeginRequest event. Is it enough? or better do a http module?
Thank you.
UPD
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo(AppSettings.UsedCulture)
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
Dim retUrl As String
....
some code
....
'Dim app As HttpApplication = CType(sender, HttpApplication)
'app.Context.RewritePath(retUrl)
Dim myContext As HttpContext = HttpContext.Current
'Rewrite the internal path
myContext.RewritePath(retUrl)
End If
I am using .Net 1.1. And It must be on .Net 1.1
RewritePath does not rewrite URL.Why?
UPD2
Having decided to make addition redirect in Sub Application_BeginRequest with new rewritting url.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 IIS 7.0(及更高版本),则可以使用 IIS UrlRewrite 模块。我们已经使用它有一段时间了,没有任何抱怨。
If you're using IIS 7.0 (and newer), you can use the IIS UrlRewrite module. We've been using it for a while, and have no complaints.