使用URL重写,可以创造出友好的URL,可以一定程度隐藏查询参数,增加对搜索引擎的友好性,对旧系统的维护也很有益处。1、添加IHttpModule的实现。2、在Init(HttpApplication context)事件中注册BeginRequest事件。3、在BeginRequest事件中根据一定规则使用RewritePath方法进行重写。以下是代码部分。web.config设置 <?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="UrlMappings" type="Job.Personal.Components.UrlMappingsHandler, Job.Personal.Components" /> </configSections> <UrlMappings> <add match="Jobs\/([a-fA-F0-9]{32}|([a-fA-F0-9]{8})-([a-fA-F0-9]{4})-([a-fA-F0-9]{4})-([a-fA-F0-9]{4})-([a-fA-F0-9]{12}))\/viewjob.aspx" replace="Con001_ProjectManage/Job/viewjob.aspx?id=$1" /> <add match="Jobs\/([a-fA-F0-9]{32}|([a-fA-F0-9]{8})-([a-fA-F0-9]{4})-([a-fA-F0-9]{4})-([a-fA-F0-9]{4})-([a-fA-F0-9]{12}))\/viewcompany.aspx" replace="Con001_ProjectManage/Job/viewcompany.aspx?id=$1" /> </UrlMappings> <system.web> <httpModules> <add type="Job.Personal.Components.UrlHandlerModule, Job.Personal.Components" name="UrlHandlerModule" /> </httpModules> </system.web></configuration> IHttpModule的实现 public class UrlHandlerModule : IHttpModule} 4、如果要为gif,jpg等非aspx,asmx之类的资源进行映射时,需要配置IIS映射到这些扩展名上,否则不能被解析。 相关文章: