C# Asp.net URL路由到第三方链接

C# Asp.net URL路由到第三方链接,c#,asp.net,iis,C#,Asp.net,Iis,我有一个Asp.net网站,需要实现url别名功能 ->应发送到外部url,如www.sales.com ->应发送至www.timesheet.com 有没有一种方法可以在不为IIS中的每个快捷方式创建应用程序的情况下实现这一点 使用Web.config或数据库的解决方案将非常理想。是的,您可以在Web.config文件中使用“重写” www.timesheet.com配置文件也是如此 注意:如果要替换完整的url{HTTP_HOST},则此代码为, 您可以做同样的更改{HTTP_HOST}/

我有一个Asp.net网站,需要实现url别名功能

->应发送到外部url,如www.sales.com

->应发送至www.timesheet.com

有没有一种方法可以在不为IIS中的每个快捷方式创建应用程序的情况下实现这一点


使用Web.config或数据库的解决方案将非常理想。

是的,您可以在Web.config文件中使用“重写”

www.timesheet.com配置文件也是如此

注意:如果要替换完整的url{HTTP_HOST},则此代码为, 您可以做同样的更改{HTTP_HOST}/{R:1}。根据您接收的条件,您可以设置正确的条件


根据你的描述。我建议您可以使用URL重写使您输入的URL重定向到另一个URL。如果您希望转到www.sales.com和www.timesheet.com,可以直接在web.config文件中添加以下内容:

    <system.webServer>
     <rewrite>
        <rules>
     <rule name="test1" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="(.*)/sf" />
                        </conditions>
                        <action type="Redirect" url="http://www.sales.com" redirectType="Found" />
                    </rule> 
 <rule name="test2" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="(.*)/ts" />
                    </conditions>
                    <action type="Redirect" url="http://www.timesheet.com" redirectType="Found" />

                </rule> 

        </rules>
    </rewrite>
    </system.webServer>

如果没有IIS,您甚至希望如何使用ASP.NET?还有,你试过什么?这应该是非常简单的,有很多信息在线哦!我忘了从我的代码中删除它@camilotereventoi我明白你的意思了。但对我来说,我所尝试创建的基本上是其他网站的快捷方式。当用户键入www.myweb.net/sf时,它将带到sales.com;当用户键入www.myweb.net/ts时,它将带到www.timesheet.com等等..所以您可以使用我提供的代码进行操作,只需在web中搜索,如何根据您的规范添加新条件。。。请记住{R:1}是您要修改的条件,因此它应该是内部条件,例如:,只需使用您的大脑并进行一些测试。我没有测试,因为我没有时间,但这就是我的想法@GaneshChandrasekaranAfter在安装URL重写模块后,上面的代码工作得非常出色。谢谢张白兰度。
    <system.webServer>
     <rewrite>
        <rules>
     <rule name="test1" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="(.*)/sf" />
                        </conditions>
                        <action type="Redirect" url="http://www.sales.com" redirectType="Found" />
                    </rule> 
 <rule name="test2" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="(.*)/ts" />
                    </conditions>
                    <action type="Redirect" url="http://www.timesheet.com" redirectType="Found" />

                </rule> 

        </rules>
    </rewrite>
    </system.webServer>