2

プロジェクトで URL 書き換えを実装しています。URL Rewrite を使用して IIS から書き換えるルールを追加しました。以下は、ルールが追加された web.config ファイルのコードです。

<system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <rewrite>
            <rules>
                <rule name="URLRedirect" stopProcessing="true">
                    <match url="^([a-z0-9/]+).aspx$" />
                    <action type="Redirect" url="{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

しかし、問題は、.aspx という拡張子だけを削除するルールを書いていて、URL を次のようにしたいことです。

http://localhost:58370/URLRedirect/Default.

しかし、現在、http://localhost:58370/URLRedirect/ この問題を解決するにはどうすればよいか.....と表示されています。

4

2 に答える 2

7

最後に、ファイルから .aspx 拡張子を削除するという問題を解決できました。URL を次のようにしたかった http://localhost:58370/ShowPage:http://localhost:58370/ShowPage.aspx

1)ShowPage という名前のフォルダー内に ShowPage.aspx ページを追加しました。2) web.config ファイルに追加したルールは次のとおりです。

 <rewrite>
          <rules>
            <clear />
            <rule name="Redirect to clean URL" enabled="true" stopProcessing="true">
              <match url="^([a-z0-9/]+).aspx$" ignoreCase="true" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Redirect" url="{R:1}" />
            </rule>
            <rule name="RewriteASPX" enabled="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Rewrite" url="{R:1}.aspx" />
            </rule>
          </rules>
        </rewrite>
于 2013-09-23T09:06:12.350 に答える
1

You can do it this way.

Install-Package Microsoft.AspNet.FriendlyUrls

Then Add Global.asax file in your application

void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}

Test your application, you would see that the .aspx extension has been removed.

于 2021-08-09T19:59:39.150 に答える