Esempio n. 1
0
		public void ProcessRequest(HttpContext context)
		{
			var request = context.Request;
			var response = context.Response;

			var httpReq = new HttpRequestWrapper("NotFoundHttpHandler", request);
			if (!request.IsLocal)
			{
				ProcessRequest(httpReq, new HttpResponseWrapper(response), null);
				return;
			}

            Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl);

			var sb = new StringBuilder();
			sb.AppendLine("Handler for Request not found: \n\n");

			sb.AppendLine("Request.ApplicationPath: " + request.ApplicationPath);
			sb.AppendLine("Request.CurrentExecutionFilePath: " + request.CurrentExecutionFilePath);
			sb.AppendLine("Request.FilePath: " + request.FilePath);
			sb.AppendLine("Request.HttpMethod: " + request.HttpMethod);
			sb.AppendLine("Request.MapPath('~'): " + request.MapPath("~"));
			sb.AppendLine("Request.Path: " + request.Path);
			sb.AppendLine("Request.PathInfo: " + request.PathInfo);
			sb.AppendLine("Request.ResolvedPathInfo: " + httpReq.PathInfo);
			sb.AppendLine("Request.PhysicalPath: " + request.PhysicalPath);
			sb.AppendLine("Request.PhysicalApplicationPath: " + request.PhysicalApplicationPath);
			sb.AppendLine("Request.QueryString: " + request.QueryString);
			sb.AppendLine("Request.RawUrl: " + request.RawUrl);
			try
			{
				sb.AppendLine("Request.Url.AbsoluteUri: " + request.Url.AbsoluteUri);
				sb.AppendLine("Request.Url.AbsolutePath: " + request.Url.AbsolutePath);
				sb.AppendLine("Request.Url.Fragment: " + request.Url.Fragment);
				sb.AppendLine("Request.Url.Host: " + request.Url.Host);
				sb.AppendLine("Request.Url.LocalPath: " + request.Url.LocalPath);
				sb.AppendLine("Request.Url.Port: " + request.Url.Port);
				sb.AppendLine("Request.Url.Query: " + request.Url.Query);
				sb.AppendLine("Request.Url.Scheme: " + request.Url.Scheme);
				sb.AppendLine("Request.Url.Segments: " + request.Url.Segments);
			}
			catch (Exception ex)
			{
				sb.AppendLine("Request.Url ERROR: " + ex.Message);
			}
			if (IsIntegratedPipeline.HasValue)
				sb.AppendLine("App.IsIntegratedPipeline: " + IsIntegratedPipeline);
			if (!WebHostPhysicalPath.IsNullOrEmpty())
				sb.AppendLine("App.WebHostPhysicalPath: " + WebHostPhysicalPath);
			if (!WebHostRootFileNames.IsEmpty())
				sb.AppendLine("App.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
			if (!ApplicationBaseUrl.IsNullOrEmpty())
				sb.AppendLine("App.ApplicationBaseUrl: " + ApplicationBaseUrl);
			if (!DefaultRootFileName.IsNullOrEmpty())
				sb.AppendLine("App.DefaultRootFileName: " + DefaultRootFileName);
			if (!DefaultHandler.IsNullOrEmpty())
				sb.AppendLine("App.DefaultHandler: " + DefaultHandler);
			if (!SStackHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
				sb.AppendLine("App.DebugLastHandlerArgs: " + SStackHttpHandlerFactory.DebugLastHandlerArgs);

			response.ContentType = "text/plain";
			response.StatusCode = 404;
            response.EndHttpHandlerRequest(skipClose:true, afterBody: r => r.Write(sb.ToString()));
		}
Esempio n. 2
0
        public void ProcessRequest(HttpContext context)
        {
            var request  = context.Request;
            var response = context.Response;

            var httpReq = new HttpRequestWrapper("NotFoundHttpHandler", request);

            if (!request.IsLocal)
            {
                ProcessRequest(httpReq, new HttpResponseWrapper(response), null);
                return;
            }

            Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl);

            var sb = new StringBuilder();

            sb.AppendLine("Handler for Request not found: \n\n");

            sb.AppendLine("Request.ApplicationPath: " + request.ApplicationPath);
            sb.AppendLine("Request.CurrentExecutionFilePath: " + request.CurrentExecutionFilePath);
            sb.AppendLine("Request.FilePath: " + request.FilePath);
            sb.AppendLine("Request.HttpMethod: " + request.HttpMethod);
            sb.AppendLine("Request.MapPath('~'): " + request.MapPath("~"));
            sb.AppendLine("Request.Path: " + request.Path);
            sb.AppendLine("Request.PathInfo: " + request.PathInfo);
            sb.AppendLine("Request.ResolvedPathInfo: " + httpReq.PathInfo);
            sb.AppendLine("Request.PhysicalPath: " + request.PhysicalPath);
            sb.AppendLine("Request.PhysicalApplicationPath: " + request.PhysicalApplicationPath);
            sb.AppendLine("Request.QueryString: " + request.QueryString);
            sb.AppendLine("Request.RawUrl: " + request.RawUrl);
            try
            {
                sb.AppendLine("Request.Url.AbsoluteUri: " + request.Url.AbsoluteUri);
                sb.AppendLine("Request.Url.AbsolutePath: " + request.Url.AbsolutePath);
                sb.AppendLine("Request.Url.Fragment: " + request.Url.Fragment);
                sb.AppendLine("Request.Url.Host: " + request.Url.Host);
                sb.AppendLine("Request.Url.LocalPath: " + request.Url.LocalPath);
                sb.AppendLine("Request.Url.Port: " + request.Url.Port);
                sb.AppendLine("Request.Url.Query: " + request.Url.Query);
                sb.AppendLine("Request.Url.Scheme: " + request.Url.Scheme);
                sb.AppendLine("Request.Url.Segments: " + request.Url.Segments);
            }
            catch (Exception ex)
            {
                sb.AppendLine("Request.Url ERROR: " + ex.Message);
            }
            if (IsIntegratedPipeline.HasValue)
            {
                sb.AppendLine("App.IsIntegratedPipeline: " + IsIntegratedPipeline);
            }
            if (!WebHostPhysicalPath.IsNullOrEmpty())
            {
                sb.AppendLine("App.WebHostPhysicalPath: " + WebHostPhysicalPath);
            }
            if (!WebHostRootFileNames.IsEmpty())
            {
                sb.AppendLine("App.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
            }
            if (!ApplicationBaseUrl.IsNullOrEmpty())
            {
                sb.AppendLine("App.ApplicationBaseUrl: " + ApplicationBaseUrl);
            }
            if (!DefaultRootFileName.IsNullOrEmpty())
            {
                sb.AppendLine("App.DefaultRootFileName: " + DefaultRootFileName);
            }
            if (!DefaultHandler.IsNullOrEmpty())
            {
                sb.AppendLine("App.DefaultHandler: " + DefaultHandler);
            }
            if (!SStackHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
            {
                sb.AppendLine("App.DebugLastHandlerArgs: " + SStackHttpHandlerFactory.DebugLastHandlerArgs);
            }

            response.ContentType = "text/plain";
            response.StatusCode  = 404;
            response.EndHttpHandlerRequest(skipClose: true, afterBody: r => r.Write(sb.ToString()));
        }
        // Entry point for ASP.NET
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            DebugLastHandlerArgs = requestType + "|" + url + "|" + pathTranslated;
            var httpReq = new HttpRequestWrapper(pathTranslated, context.Request);

            foreach (var rawHttpHandler in RawHttpHandlers)
            {
                var reqInfo = rawHttpHandler(httpReq);
                if (reqInfo != null)
                {
                    return(reqInfo);
                }
            }

            var mode     = EndpointHost.Config.SStackHandlerFactoryPath;
            var pathInfo = context.Request.GetPathInfo();

            //WebDev Server auto requests '/default.aspx' so recorrect path to different default document
            if (mode == null && (url == "/default.aspx" || url == "/Default.aspx"))
            {
                pathInfo = "/";
            }

            //Default Request /
            if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/")
            {
                //Exception calling context.Request.Url on Apache+mod_mono
                if (ApplicationBaseUrl == null)
                {
                    var absoluteUrl = Env.IsMono ? url.ToParentPath() : context.Request.GetApplicationUrl();
                    SetApplicationBaseUrl(absoluteUrl);
                }

                //e.g. CatchAllHandler to Process Markdown files
                var catchAllHandler = GetCatchAllHandlerIfAny(httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath());
                if (catchAllHandler != null)
                {
                    return(catchAllHandler);
                }

                return(ServeDefaultHandler ? DefaultHttpHandler : NonRootModeDefaultHttpHandler);
            }

            if (mode != null && pathInfo.EndsWith(mode))
            {
                var requestPath = context.Request.Path.ToLower();
                if (requestPath == "/" + mode ||
                    requestPath == mode ||
                    requestPath == mode + "/")
                {
                    if (context.Request.PhysicalPath != WebHostPhysicalPath ||
                        !File.Exists(Path.Combine(context.Request.PhysicalPath, DefaultRootFileName ?? "")))
                    {
                        return(new IndexPageHttpHandler());
                    }
                }

                var okToServe = ShouldAllow(context.Request.FilePath);
                return(okToServe ? DefaultHttpHandler : ForbiddenHttpHandler);
            }

            return(GetHandlerForPathInfo(
                       context.Request.HttpMethod, pathInfo, context.Request.FilePath, pathTranslated)
                   ?? NotFoundHttpHandler);
        }
        // Entry point for ASP.NET
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            DebugLastHandlerArgs = requestType + "|" + url + "|" + pathTranslated;
            var httpReq = new HttpRequestWrapper(pathTranslated, context.Request);
            foreach (var rawHttpHandler in RawHttpHandlers)
            {
                var reqInfo = rawHttpHandler(httpReq);
                if (reqInfo != null) return reqInfo;
            }

            var mode = EndpointHost.Config.SStackHandlerFactoryPath;
            var pathInfo = context.Request.GetPathInfo();

            //WebDev Server auto requests '/default.aspx' so recorrect path to different default document
            if (mode == null && (url == "/default.aspx" || url == "/Default.aspx"))
                pathInfo = "/";

            //Default Request /
            if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/")
            {
                //Exception calling context.Request.Url on Apache+mod_mono
                if (ApplicationBaseUrl == null)
                {
                    var absoluteUrl = Env.IsMono ? url.ToParentPath() : context.Request.GetApplicationUrl();
                    SetApplicationBaseUrl(absoluteUrl);
                }

                //e.g. CatchAllHandler to Process Markdown files
                var catchAllHandler = GetCatchAllHandlerIfAny(httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath());
                if (catchAllHandler != null) return catchAllHandler;

                return ServeDefaultHandler ? DefaultHttpHandler : NonRootModeDefaultHttpHandler;
            }

            if (mode != null && pathInfo.EndsWith(mode))
            {
                var requestPath = context.Request.Path.ToLower();
                if (requestPath == "/" + mode
                    || requestPath == mode
                    || requestPath == mode + "/")
                {
                    if (context.Request.PhysicalPath != WebHostPhysicalPath
                        || !File.Exists(Path.Combine(context.Request.PhysicalPath, DefaultRootFileName ?? "")))
                    {
                        return new IndexPageHttpHandler();
                    }
                }

                var okToServe = ShouldAllow(context.Request.FilePath);
                return okToServe ? DefaultHttpHandler : ForbiddenHttpHandler;
            }

            return GetHandlerForPathInfo(
                context.Request.HttpMethod, pathInfo, context.Request.FilePath, pathTranslated)
                   ?? NotFoundHttpHandler;
        }