如何知道URL重写后,原来的网址是什么? [英] How to know the original url after url rewrite?
问题描述
我有一个重定向www.domain2.com一个domain1.com的根目录下的子目录下,URL重写(我们称之为文件夹子项目)。在我的控制器,我需要构建一个URL到原来的非修改的路径,但Request.Url属性(比如绝对URI或localPath来)总是包含子项目子文件夹。
I have url rewrite rules which redirect www.domain2.com to a subfolder under the root of a domain1.com (let's call this folder subproject). In my controller, I need to construct a URL to the original non modified path but the Request.Url properties (like AbsoluteUri or LocalPath) always contain the subproject subfolder.
在换句话说,如果用户键入:
In other words, if the user typed:
www.domain2.com/controller/action
urlrewrite使得它:
urlrewrite makes it:
www.domain1.com/subproject/controller/action
和我要重建原始网址:
www.domain2.com/controller/action
我可以硬code从URL中移除子项目,并开始与域2中的网址,但我需要一个通用的一块code,因为这个网址的重建将是一个可重用的库。域2可以在我的应用程序有关的子文件夹的设置,但是什么?
I could hardcode the removal of subproject from the url and begin the url with domain2 but I need a generic piece of code because this url reconstruction will be in a reusable library. domain2 could be in the settings of my app but what about the subfolder?
在引用,这里是重写规则:
In reference, here is the rewrite rule:
<rewrite>
<rules>
<rule name="Redirect to subproject">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?domain2.com" />
<add input="{PATH_INFO}" pattern="^/subproject/" negate="true" />
</conditions>
<action type="Rewrite" url="\subproject\{R:0}" />
</rule>
</rules>
</rewrite>
感谢您
推荐答案
您应该能发现它在<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.htt$p$pquest.rawurl.aspx\">Request.RawUrl.
这篇关于如何知道URL重写后,原来的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!