webform 的路由
生活随笔
收集整理的這篇文章主要介紹了
webform 的路由
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
webform是怎么通過url找到對應handler的呢?
mvc 和webapi的路由都是通過注冊到RouteTable.Routes中,然后在urlroutingmodule中路由到對應routehander,那以前webform程序沒有注冊路由又是怎么找到對應的handler的呢?
在httpapplication中注冊事件中有一個MapHandlerExecutionStep
internal override void BuildSteps(WaitCallback stepCallback){.......arrayList.Add(new HttpApplication.MapHandlerExecutionStep(application));......}在這個事件中
void HttpApplication.IExecutionStep.Execute(){........context.Handler = this._application.MapHttpHandler(context, request.RequestType, request.FilePathObject, request.PhysicalPathInternal, false);......} // System.Web.HttpApplication internal IHttpHandler MapHttpHandler(HttpContext context, string requestType, VirtualPath path, string pathTranslated, bool useAppConfig) {IHttpHandler httpHandler = (context.ServerExecuteDepth == 0) ? context.RemapHandlerInstance : null;using (new ApplicationImpersonationContext()){if (httpHandler != null){return httpHandler;}HttpHandlerAction handlerMapping = this.GetHandlerMapping(context, requestType, path, useAppConfig);........//根據請求信息包裝對應工廠類并放入緩存中,每次從緩存中獲取IHttpHandlerFactory factory = this.GetFactory(handlerMapping);try{
//獲取handlerIHttpHandlerFactory2 httpHandlerFactory = factory as IHttpHandlerFactory2;if (httpHandlerFactory != null){httpHandler = httpHandlerFactory.GetHandler(context, requestType, path, pathTranslated);}else{httpHandler = factory.GetHandler(context, requestType, path.VirtualPathString, pathTranslated);}}.........}return httpHandler; }
所以每次webform或者handler請求后都會從緩存中獲取工廠類然后獲取對應的handler
如何實現webform友好訪問呢?
現在webform新建程序都會自動添加像mvc路由一樣的路由注冊文件
public class Global : HttpApplication{void Application_Start(object sender, EventArgs e){// 在應用程序啟動時運行的代碼 RouteConfig.RegisterRoutes(RouteTable.Routes);BundleConfig.RegisterBundles(BundleTable.Bundles);}} public static class RouteConfig{public static void RegisterRoutes(RouteCollection routes){var settings = new FriendlyUrlSettings();settings.AutoRedirectMode = RedirectMode.Permanent;routes.EnableFriendlyUrls(settings);}}?
轉載于:https://www.cnblogs.com/NNYang/p/11006394.html
總結
以上是生活随笔為你收集整理的webform 的路由的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flutter 中的基本路由
- 下一篇: 使用nsenter进入docker容器后