示例环境:VS2010
要求:
重写前:http://localhost:13275/Default.aspx?username=wilson
重写后:http://localhost:13275/wilson
第一步:下载相关DLL
第二步:VS2010创建测试网站应用程序,并添加以上DLL的引用
第三步:在项目中添加asp.net文件(App_Browsers)
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.HtmlControls.HtmlForm"
adapterType="URLRewriter.Form.FormRewriterControlAdapter" />
</controlAdapters>
</browser>
</browsers>
第四步:配置web.config
<configSections>
<section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter"/>
</configSections>
<CustomConfiguration>
<urls>
<!--([\w]+)表示,1到n个字母或数字或下划线或汉字组成-->
<add virtualUrl="~/([\w]+)*" destinationUrl="~/Default.aspx?username=$1"/>
</urls>
</CustomConfiguration>
<httpModules>
<add type="URLRewriter.RewriterModule, URLRewriter" name="RewriterModule"/>
</httpModules>
第五步:测式
if (!IsPostBack)
{
StringBuilder sb = new StringBuilder();
sb.Append("当前所在位置:Default.aspx<br/>");
if (!string.IsNullOrEmpty(Request.Params["username"]))
{
sb.Append("所接收到的参数username:" + Request.Params["username"]);
}
Response.Write(sb.ToString());
}
所接收到的参数username:wilson
1171




被折叠的 条评论
为什么被折叠?



