c# - Asp.net URL 路由到第三方链接
问题描述
我有一个 Asp.net 网站,需要实现 url 别名功能
http://myweb.net/sf --> 应该路由到外部 url,比如 www.sales.com
http://myweb.net/ts --> 应该路由到 www.timesheet.com
有没有办法在 IIS 中不创建应用程序(对于每个快捷方式)来实现这一点?
使用 Web.config 或数据库的解决方案将是理想的。
解决方案
根据你的描述。我建议您可以使用 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>
推荐阅读
- java - 调用HSQLDB jar中DatabaseManagerSwing类的main方法后如何获取窗口关闭事件?
- c# - 如何从二维数组创建和写入图像?
- java - 如何为每个请求项创建多个线程
- vue.js - 在 Vue 中完全重新加载 div?
- javascript - 从单独的 url 反向链接自动滚动到主页(根)页面的特定部分
- swiftui - 如何导航出 ActionSheet?
- java - Java Swing TextArea:如何在输出 TextArea 中同时打印音译文本?
- javascript - 在椭圆中画一个矩形
- php - Asterisk PAMI 发起出站呼叫问题 (PHP)
- javascript - 如何在 ES5 文件中模拟 axios 请求?