Response.Redirect的页面上使用URL由IIS URL重写模块改写 [英] Response.Redirect on Page with Url Rewritten by IIS Url Rewrite Module

查看:472
本文介绍了Response.Redirect的页面上使用URL由IIS URL重写模块改写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是IIS URL重写模块改写为我的ASP.Net Web应用程序的URL 。网址正在从改写:

I am using the IIS Url Rewrite module to rewrite urls for my ASP.Net web application. The Urls are being rewritten from:

HTTP://domain/version/page.aspx

HTTP://domain/company/page.aspx

和直接浏览使用绝对路径时,它工作得很好。问题来使用相对路径应用程序内航行时英寸的任何的那种相对路径。

And it works just fine when browsing directly using absolute paths. The problem comes in when navigating within the app using relative paths. any kind of relative path.

所有的相对路径重定向到相应的 HTTP://domain/version/page.aspx ,而不是在的http://域名/公司/ page.aspx ,应该去。

All relative paths redirect to the corresponding http://domain/version/page.aspx instead of to the http://domain/COMPANY/page.aspx that it should be going to.

我解决了很多问题的方法通过在Global.asax中添加此行到BeginRequest事件:

I solved a lot of the issue by adding this line to the BeginRequest event in Global.asax:

Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
    HttpContext.Current.RewritePath(HttpContext.Current.Request.Url.AbsolutePath, True)
End Sub

从本质上讲它只是衍合的虚拟路径所请求的URL。

Essentially it is just rebasing the virtual path to the requested url.

不过,即使与Response.Redirect的STILL重定向到实际的路径,而不是虚拟路径。

But even with that Response.Redirect STILL redirects to the actual path and not the virtual path.

所以这code:的Response.Redirect(〜/ Test.aspx文件)将重定向到域/版本/测试。 ASPX 而不是域/公司/ Test.aspx文件

So this code: Response.Redirect("~/test.aspx") will redirect to domain/Version/test.aspx instead of domain/Company/test.aspx

如何让我的Response.Redirect重定向到虚拟路径(域/公司/ Test.aspx文件),而不是实际的路径(域/ VERSION / Test.aspx文件

How do I make Response.Redirect redirect to the virtual path (domain/COMPANY/test.aspx) instead of to the actual path (domain/VERSION/test.aspx)

感谢。

推荐答案

两个选项。你可以这样做:

Two options. You can either do:

Response.Redirect("/company/test.aspx")

Response.Redirect("http://domain/company/test.aspx")

这是你必须处理,如果你要使用他们的使用动态URL的挑战之一,和一个。

This is one of the challenges of using dynamic URLS, and one that you have to deal with if you are going to use them.

也许是最好的解决方法是编写一个函数,所有页面可以看到,这是否适合你。这样,你可以这样写:

Probably the best solution is to write a function that all of your pages can see that does this for you. That way you can just write:

MyRedirectFunction("test.aspx")

和所有的细节都在幕后。

and all the details are behind the scenes.

这篇关于Response.Redirect的页面上使用URL由IIS URL重写模块改写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆