重写 Global.asax、ASP.NET 中的 url

发布于 2024-09-27 17:38:10 字数 962 浏览 1 评论 0原文

你好。我需要将双斜杠替换为一个斜杠。我计划在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶色山野 2024-10-04 17:38:10

如果您使用的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文