url重写后如何知道原始url? [英] How to know the original url after url rewrite?

查看:43
本文介绍了url重写后如何知道原始url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 url 重写规则,将 www.domain2.com 重定向到 domain1.com 根目录下的子文件夹(我们称此文件夹为子项目).在我的控制器中,我需要构造一个指向原始未修改路径的 URL,但 Request.Url 属性(如 AbsoluteUri 或 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

我可以硬编码从 url 中删除子项目,并以 domain2 开始 url,但我需要一段通用代码,因为这个 url 重建将在一个可重用的库中.domain2 可以在我应用的设置中,但是子文件夹呢?

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>

谢谢

推荐答案

您应该能够在 Request.RawUrl.

这篇关于url重写后如何知道原始url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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