Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 响应。使用IIS Url重写模块重写的Url在页面上重定向_Asp.net_Iis 7_Url Rewriting - Fatal编程技术网

Asp.net 响应。使用IIS Url重写模块重写的Url在页面上重定向

Asp.net 响应。使用IIS Url重写模块重写的Url在页面上重定向,asp.net,iis-7,url-rewriting,Asp.net,Iis 7,Url Rewriting,我正在使用IIS模块重写ASP.Net web应用程序的URL。正在从以下地址重写URL: http://domain/version/page.aspx 到 http://domain/company/page.aspx 当直接使用绝对路径浏览时,它工作得很好。使用相对路径在应用程序内导航时会出现问题。任何一种相对路径 所有相对路径重定向到相应的http://domain/version/page.aspx而不是转到http://domain/COMPANY/page.aspx它应该是 通过在

我正在使用IIS模块重写ASP.Net web应用程序的URL。正在从以下地址重写URL:

http://domain/version/page.aspx

http://domain/company/page.aspx

当直接使用绝对路径浏览时,它工作得很好。使用相对路径在应用程序内导航时会出现问题。任何一种相对路径

所有相对路径重定向到相应的
http://domain/version/page.aspx
而不是转到
http://domain/COMPANY/page.aspx
它应该是

通过在Global.asax中的BeginRequest事件中添加这一行,我解决了很多问题:

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

但是即使有了这个响应,重定向仍然重定向到实际路径而不是虚拟路径

所以这个代码:
Response.Redirect(“~/test.aspx”)
将重定向到
domain/Version/test.aspx
,而不是
domain/Company/test.aspx

如何做出响应。重定向到虚拟路径(
domain/COMPANY/test.aspx
),而不是实际路径(
domain/VERSION/test.aspx


谢谢。

两种选择。您可以执行以下任一操作:

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

这是使用动态URL的挑战之一,如果要使用动态URL,就必须解决这个问题

也许最好的解决方案是编写一个所有页面都能看到的函数,为您实现这一点。这样你就可以写:

MyRedirectFunction("test.aspx")

所有的细节都在幕后。

这就是我要走的路。。。遗憾的是,这是唯一的好办法。
MyRedirectFunction("test.aspx")