第一步:建立一個類,並整合自IRouteHandler,實現介面中的方法.
第二步:在Application_Start中註冊Route
第三步: 配置Web.Config:
1.在<system.web>中添加
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpModules>
下面為了為了支援iis7
2、在<system.WebServer>中添加
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web,Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
或者
1. System.Web->HttpModules->
<add
name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,System.Web.Routing,
Version=3.5.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
2. system.webServer->modules->
<add
name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing,Version=3.5.0.0,
Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
3. system.webServer->handlers->
<add
name="MyRoutingHandler"
verb="*"
path="UrlRouting.axd"
type="XXX.MyRoutingHandler"/>
如果sesstion不能用
參考http://stackoverflow.com/questions/218057/httpcontext-current-session-is-null-when-routing-requests