重写Url(http://www.yousite.com/productdetail/123456.htm)

重写Url大概步骤分为以下三个

1.在web.config里面设置verb动作。

2.后台处理类YourCommonUrlRewriter.cs,截取相应参数做处理

3.前台跳转链接类似路径是这样的跳转方式 path="*/,*.htm,*/*.htm,*/*/*.htm" 。

 

1.在web.config里面设置verb动作。

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="GET,HEAD,POST" path="*/,*.htm,*/*.htm,*/*/*.htm" type="YourCommonUrlRewriter"/>
<!--<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>-->
</httpHandlers>

 2.后台处理类YourCommonUrlRewriter.cs,截取相应参数做处理 。

string requestUrl = context.Request.Url.AbsolutePath;
if (string.IsNullOrEmpty(requestUrl))
{
context.Response.Redirect("/");
return;
}
if (requestUrl.Contains(".htm"))
{
requestUrl = requestUrl.Replace(".htm", "");
}
string[] strs = requestUrl.Split('/');
if (strs.Length<3)
{
context.Response.Redirect("/");
return;
}

// /action/index.htm
string action = strs[1];

后续为根据对应action参数做逻辑处理。

3.前台跳转链接类似路径是这样的跳转方式 path="*/,*.htm,*/*.htm,*/*/*.htm" 。

 <a href="/productdetail/{@id}.htm" title="{@title}" target="_blank">

 

 

posted @ 2013-11-08 09:52  sundy.yip  阅读(425)  评论(0编辑  收藏  举报