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

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

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

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

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

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


互换的青春
浏览 96回答 2
2回答

PIPIONE

根据你的描述。我建议你可以使用 URL 重写来使你输入的 url 重定向到另一个。如果你想路由&nbsp;http://myweb.net/sf&nbsp;到 www.sales.com 和http://myweb.net/ts&nbsp;到 www.timesheet.com,你可以直接在你的 web.config 文件中添加以下内容:&nbsp;<system.webServer>&nbsp; &nbsp; &nbsp;<rewrite>&nbsp; &nbsp; &nbsp; &nbsp; <rules>&nbsp; &nbsp; &nbsp;<rule name="test1" stopProcessing="true">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <match url="(.*)" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add input="{REQUEST_URI}" pattern="(.*)/sf" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <action type="Redirect" url="http://www.sales.com" redirectType="Found" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </rule>&nbsp;&nbsp;<rule name="test2" stopProcessing="true">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <match url="(.*)" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add input="{REQUEST_URI}" pattern="(.*)/ts" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <action type="Redirect" url="http://www.timesheet.com" redirectType="Found" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </rule>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </rules>&nbsp; &nbsp; </rewrite>&nbsp; &nbsp; </system.webServer>

慕哥9229398

是的,您可以在Web.Config文件中使用重写&nbsp;<rewrite>&nbsp; &nbsp; <rules><rule name="CanonicalHostNameRule">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <match url="(.*)" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add input="{HTTP_HOST}" pattern="^www\.sales\.com$" negate="true" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <action type="Redirect" url="http://www.sales.com/{R:1}" />&nbsp; &nbsp; &nbsp; &nbsp; </rule>&nbsp; &nbsp; </rules></rewrite>www.timesheet.com配置文件也一样注意:这段代码是如果你想替换完整的 url {HTTP_HOST},你可以根据你接收到的条件做同样的改变{HTTP_HOST}/{R:1},你设置正确的
打开App,查看更多内容
随时随地看视频慕课网APP