public IServiceStackHandler GetNotFoundHandler()
        {
            IServiceStackHandler httpHandler = null;

            CustomErrorHttpHandlers?.TryGetValue(HttpStatusCode.NotFound, out httpHandler);

            return(httpHandler ?? new NotFoundHttpHandler());
        }
        public IServiceStackHandler GetCustomErrorHandler(HttpStatusCode errorStatus)
        {
            IServiceStackHandler httpHandler = null;

            CustomErrorHttpHandlers?.TryGetValue(errorStatus, out httpHandler);

            return(httpHandler);
        }
Пример #3
0
        public IServiceStackHandler GetCustomErrorHandler(HttpStatusCode errorStatus)
        {
            IServiceStackHandler httpHandler = null;

            if (CustomErrorHttpHandlers != null)
            {
                CustomErrorHttpHandlers.TryGetValue(errorStatus, out httpHandler);
            }
            return(httpHandler ?? Config.GlobalHtmlErrorHttpHandler);
        }
        public IServiceStackHandler GetCustomErrorHandler(HttpStatusCode errorStatus)
        {
            IServiceStackHandler httpHandler = null;

            if (CustomErrorHttpHandlers != null)
            {
                CustomErrorHttpHandlers.TryGetValue(errorStatus, out httpHandler);
            }

            switch (errorStatus)
            {
            case HttpStatusCode.Forbidden:
                return(httpHandler ?? new ForbiddenHttpHandler());

            case HttpStatusCode.NotFound:
                return(httpHandler ?? new NotFoundHttpHandler());
            }

            return(httpHandler);
        }
 public ServiceStackHttpHandler(IServiceStackHandler servicestackHandler)
 {
     this.servicestackHandler = servicestackHandler;
 }
Пример #6
0
 public ServiceStackHttpHandler(IServiceStackHandler servicestackHandler)
 {
     this.servicestackHandler = servicestackHandler;
 }
        internal static void Init()
        {
            var appHost = HostContext.AppHost;

            WebHostPhysicalPath = appHost.VirtualFileSources.RootDirectory.RealPath;

            //Apache+mod_mono treats path="servicestack*" as path="*" so takes over root path, so we need to serve matching resources
            var hostedAtRootPath = appHost.Config.HandlerFactoryPath.IsNullOrEmpty();

//#if !NETSTANDARD2_0
//            //DefaultHttpHandler not supported in IntegratedPipeline mode
//            if (!Platform.IsIntegratedPipeline && HostContext.IsAspNetHost && !hostedAtRootPath && !Env.IsMono)
//                DefaultHttpHandler = new DefaultHttpHandler();
//#endif
            var rootFiles = appHost.VirtualFileSources.GetRootFiles();

            DefaultRootFileName = null;
            foreach (var file in rootFiles)
            {
                var fileNameLower = file.Name.ToLowerInvariant();
                if (DefaultRootFileName == null && appHost.Config.DefaultDocuments.Contains(fileNameLower))
                {
                    //Can't serve Default.aspx pages so ignore and allow for next default document
                    if (!fileNameLower.EndsWith(".aspx"))
                    {
                        DefaultRootFileName = file.Name;
                        StaticFileHandler.SetDefaultFile(file.VirtualPath, file.ReadAllBytes(), file.LastModified);

                        if (DefaultHttpHandler == null)
                        {
                            DefaultHttpHandler = new StaticFileHandler(file);
                        }
                    }
                }
            }

            if (!appHost.Config.DefaultRedirectPath.IsNullOrEmpty())
            {
                DefaultHttpHandler = new RedirectHttpHandler {
                    RelativeUrl = appHost.Config.DefaultRedirectPath
                }
            }
            ;

            var metadataHandler = new RedirectHttpHandler();

            if (!appHost.Config.MetadataRedirectPath.IsNullOrEmpty())
            {
                metadataHandler.RelativeUrl = appHost.Config.MetadataRedirectPath;
            }
            else
            {
                metadataHandler.RelativeUrl = "metadata";
            }
            if (hostedAtRootPath)
            {
                if (DefaultHttpHandler == null)
                {
                    DefaultHttpHandler = metadataHandler;
                }
            }
            else
            {
                DefaultHttpHandler = metadataHandler;
            }

            var defaultRedirectHanlder = DefaultHttpHandler as RedirectHttpHandler;
            var debugDefaultHandler    = defaultRedirectHanlder?.RelativeUrl;

            ForbiddenHttpHandler = appHost.GetCustomErrorHttpHandler(HttpStatusCode.Forbidden) ?? new ForbiddenHttpHandler
            {
                WebHostPhysicalPath = WebHostPhysicalPath,
                WebHostUrl          = appHost.Config.WebHostUrl,
                DefaultRootFileName = DefaultRootFileName,
                DefaultHandler      = debugDefaultHandler,
            };

            NotFoundHttpHandler = appHost.GetCustomErrorHttpHandler(HttpStatusCode.NotFound) ?? new NotFoundHttpHandler
            {
                WebHostPhysicalPath = WebHostPhysicalPath,
                WebHostUrl          = appHost.Config.WebHostUrl,
                DefaultRootFileName = DefaultRootFileName,
                DefaultHandler      = debugDefaultHandler,
            };
        }
Пример #8
0
 public static IApplicationBuilder Use(this IApplicationBuilder app, IServiceStackHandler httpHandler)
 {
     return(app.Use(httpHandler.Middleware));
 }