// Entry point for ASP.NET public IHttpHandler GetHandler(HttpContext ctx, string requestType, string url, string pathTranslated) { var appHost = HostContext.AppHost; DebugLastHandlerArgs = requestType + "|" + url + "|" + pathTranslated; var httpReq = new Host.AspNet.AspNetRequest(ctx.Request.RequestContext.HttpContext, url.SanitizedVirtualPath()); foreach (var rawHttpHandler in appHost.RawHttpHandlersArray) { var handler = rawHttpHandler(httpReq); if (handler != null) { return(handler); } } var pathInfo = httpReq.PathInfo; //WebDev Server auto requests '/default.aspx' so re-correct path to different default document var mode = appHost.Config.HandlerFactoryPath; if (mode == null && (url == "/default.aspx" || url == "/Default.aspx")) { pathInfo = "/"; } //Default Request / if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/") { //RestPath matchesFallback = appHost.Config.FallbackRestPath?.Invoke(httpReq); //if (matchesFallback == null || matchesFallback.Priority > 0 || // (matchesFallback.MatchRule == null && !(matchesFallback.Priority < 0))) // is not targeted fallback //{ // //e.g. to Process View Engine requests // var catchAllHandler = GetCatchAllHandlerIfAny(appHost, httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath()); // if (catchAllHandler != null) return catchAllHandler; //} //If the fallback route can handle it, let it //if (matchesFallback != null) //{ // var sanitizedPath = RestHandler.GetSanitizedPathInfo(pathInfo, out var contentType); // return new RestHandler { RestPath = matchesFallback, RequestName = matchesFallback.RequestType.GetOperationName(), ResponseContentType = contentType }; //} //if (mode == null) // return DefaultHttpHandler; //if (DefaultRootFileName != null) // return StaticFilesHandler; return(null); // NonRootModeDefaultHttpHandler; } return(GetHandlerForPathInfo(httpReq, pathTranslated) ?? NotFoundHttpHandler); }
// Entry point for ASP.NET public IHttpHandler GetHandler(HttpContext ctx, string requestType, string url, string pathTranslated) { var appHost = HostContext.AppHost; DebugLastHandlerArgs = requestType + "|" + url + "|" + pathTranslated; var httpReq = new Host.AspNet.AspNetRequest(ctx.Request.RequestContext.HttpContext, url.SanitizedVirtualPath()); foreach (var rawHttpHandler in appHost.RawHttpHandlersArray) { var handler = rawHttpHandler(httpReq); if (handler != null) { return(handler); } } var pathInfo = httpReq.PathInfo; //WebDev Server auto requests '/default.aspx' so recorrect path to different default document var mode = appHost.Config.HandlerFactoryPath; if (mode == null && (url == "/default.aspx" || url == "/Default.aspx")) { pathInfo = "/"; } //Default Request / if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/") { //If the fallback route can handle it, let it var restPath = appHost.Config.FallbackRestPath?.Invoke(httpReq); if (restPath != null) { var sanitizedPath = RestHandler.GetSanitizedPathInfo(pathInfo, out var contentType); return(new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.GetOperationName(), ResponseContentType = contentType }); } //e.g. CatchAllHandler to Process Markdown files var catchAllHandler = GetCatchAllHandlerIfAny(appHost, httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath()); if (catchAllHandler != null) { return(catchAllHandler); } if (mode == null) { return(DefaultHttpHandler); } if (DefaultRootFileName != null) { return(StaticFilesHandler); } return(NonRootModeDefaultHttpHandler); } return(GetHandlerForPathInfo(httpReq, pathTranslated) ?? NotFoundHttpHandler); }