我在我的网络表单ASP.NET应用程序中遇到问题,我想从
重写网址进入
http://example.com/page.aspx?id=abcd
有人可以帮我提一些提示吗?
谢谢!
答案 0 :(得分: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] +)时,配置应该有效,更改模式以使其适用于数字。
希望有所帮助