亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

C#
互換的青春 2022-11-21 21:19:25
我有一個 Asp.net 網站,需要實現 url 別名功能http://myweb.net/sf --> 應該路由到外部 url,比如 www.sales.comhttp://myweb.net/ts --> 應該路由到 www.timesheet.com有沒有辦法在不在 IIS 中創建應用程序(為每個快捷方式)的情況下實現這一點?使用 Web.config 或數據庫的解決方案將是理想的。
查看完整描述

2 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

根據你的描述。我建議你可以使用 URL 重寫來使你輸入的 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>


查看完整回答
反對 回復 2022-11-21
?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

是的,您可以在Web.Config文件中使用重寫


 <rewrite>

    <rules>

<rule name="CanonicalHostNameRule">

            <match url="(.*)" />

            <conditions>

                <add input="{HTTP_HOST}" pattern="^www\.sales\.com$" negate="true" />

            </conditions>

            <action type="Redirect" url="http://www.sales.com/{R:1}" />

        </rule>

    </rules>

</rewrite>

www.timesheet.com配置文件也一樣


注意:這段代碼是如果你想替換完整的 url {HTTP_HOST},你可以根據你接收到的條件做同樣的改變{HTTP_HOST}/{R:1},你設置正確的


查看完整回答
反對 回復 2022-11-21
  • 2 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號