0

Web フォーム ASP.NET アプリに問題があり、そこから URL を書き換えたいと考えています。

http://example.com/abcd

の中へ

http://example.com/page.aspx?id=abcd

  • abcd部分は一意であり、そのためのフォルダーを作成できません
  • ユーザーに常にhttp://example.com/abcdのURLが表示されるようにしたい
  • ソリューションは Windows Azure でも同じでしょうか?

誰かヒントを教えてください。

ありがとう!

4

1 に答える 1

0

web.config の system.webServer セクションに次のように記述します。

<!-- This has been added to support url rewriting for ... -->
<rewrite>
  <rules>
    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
      <match url="^Page\.aspx$" />
      <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^id=([a-zA-Z]+)$" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="false" />
    </rule>
    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
      <match url="^([a-zA-Z]+)$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="Page.aspx?id={R:1}" />
    </rule>
  </rules>
</rewrite>

本番サイトにある構成からコピーし、少し変更したことに注意してください...テストが必要です。

構成は、単語 ([a-zA-Z]+) しかない場合に機能するはずです。パターンを変更して、数字に対して機能するようにします。

それが役に立てば幸い

于 2012-07-27T21:27:40.977 に答える