首页 > 解决方案 > Asp.net URL 路由到第三方链接

问题描述

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

http://myweb.net/sf --> 应该路由到外部 url,比如 www.sales.com

http://myweb.net/ts --> 应该路由到 www.timesheet.com

有没有办法在 IIS 中不创建应用程序(对于每个快捷方式)来实现这一点?

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

标签: c#asp.netiis

解决方案


根据你的描述。我建议您可以使用 URL rewrite 使您输入的 url 重定向到另一个。如果您想 将http://myweb.net/sf路由 到 www.sales.com 并将http://myweb.net/ts路由 到 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>

推荐阅读