簡體   English   中英

URL 在條件 ASPX、ASP.Net 的情況下無需更改文件夾即可重寫

[英]URL rewrite without folder change on condition ASPX , ASP.Net

嗨,我需要在 aspx 之間使用特定關鍵字更改我的所有 url,但不更改文件夾結構。 現在我的 url 和帶有條件的文件夾結構如下所示:

條件:isABC =false url 會像localhost55717/product/xyz.aspx但條件 isABC =true 它應該像localhost55717/abc/product/xyz.aspx

我的文件夾結構是

project
  |_WEB
    |_Default.aspx
    |_ABC
      |_Default.aspx
    |_product
      |_xyz.aspx

請幫忙。

在您的代碼中,無論您在哪里進行重定向,您都可以將 URL 指定為 localhost55717/abc/product/xyz.aspx。

在 web.config 中,您可以添加此規則。

<rule name="Rewrite" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{URL}" negate="true" pattern="isABC" />
    </conditions>
    <action type="Rewrite" url="localhost55717/product/xyz.aspx" />
</rule>
<rule name="Rewrite" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{URL}" pattern="isABC" />
    </conditions>
    <action type="Redirect" url="localhost55717/product/xyz.aspx" redirectType="Permanent" />
</rule>

Basically we have specified the URL localhost55717/abc/product/xyz.aspx in the code and in web.config based on condition we are just rewriting the URL for server or altogether redirecting it so that its visible to client as well.

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM