GetBaseUrl() публичный статический Метод

public static GetBaseUrl ( ) : string
Результат string
Пример #1
0
        public static string GetBaseUrl(this IRequest httpReq)
        {
            var baseUrl = HttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl);
            }

            var handlerPath = HostContext.Config.HandlerFactoryPath;

            if (handlerPath != null)
            {
                var absoluteUri = httpReq.AbsoluteUri;
                var pos         = absoluteUri.IndexOf(handlerPath, StringComparison.OrdinalIgnoreCase);
                if (pos >= 0)
                {
                    baseUrl = absoluteUri.Substring(0, pos + handlerPath.Length);
                    return(baseUrl);
                }
                return("/" + handlerPath);
            }

            return(new Uri(httpReq.AbsoluteUri).GetLeftPart(UriPartial.Authority)
                   .CombineWith(handlerPath)
                   .TrimEnd('/'));
        }
Пример #2
0
        public override string GetBaseUrl(IRequest httpReq)
        {
            var useHttps = UseHttps(httpReq);
            var baseUrl  = HttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl.NormalizeScheme(useHttps));
            }

            baseUrl = httpReq.AbsoluteUri.InferBaseUrl(fromPathInfo: httpReq.PathInfo);
            if (baseUrl != null)
            {
                return(baseUrl.NormalizeScheme(useHttps));
            }

            var handlerPath = Config.HandlerFactoryPath;

            var aspReq = (HttpRequestBase)httpReq.OriginalRequest;

            baseUrl = aspReq.Url.Scheme + "://" + aspReq.Url.Authority +
                      aspReq.ApplicationPath?.TrimEnd('/') + "/";

            return(baseUrl
                   .NormalizeScheme(useHttps)
                   .CombineWith(handlerPath)
                   .TrimEnd('/'));
        }
Пример #3
0
        public static string GetBaseUrl(this IRequest httpReq)
        {
            var baseUrl = HttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl.NormalizeScheme());
            }

            baseUrl = httpReq.AbsoluteUri.InferBaseUrl(fromPathInfo: httpReq.PathInfo);
            if (baseUrl != null)
            {
                return(baseUrl.NormalizeScheme());
            }

            var handlerPath = HostContext.Config.HandlerFactoryPath;

            return(new Uri(httpReq.AbsoluteUri).GetLeftPart(UriPartial.Authority)
                   .NormalizeScheme()
                   .CombineWith(handlerPath)
                   .TrimEnd('/'));
        }
Пример #4
0
        public virtual string GetBaseUrl(IRequest httpReq)
        {
            var useHttps = UseHttps(httpReq);
            var baseUrl  = HttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl.NormalizeScheme(useHttps));
            }

            baseUrl = httpReq.AbsoluteUri.InferBaseUrl(fromPathInfo: httpReq.PathInfo);
            if (baseUrl != null)
            {
                return(baseUrl.NormalizeScheme(useHttps));
            }

            var handlerPath = Config.HandlerFactoryPath;

            return(new Uri(httpReq.AbsoluteUri).GetLeftAuthority()
                   .NormalizeScheme(useHttps)
                   .CombineWith(handlerPath)
                   .TrimEnd('/'));
        }
Пример #5
0
        public static string GetBaseUrl(this IRequest httpReq)
        {
            var baseUrl = HttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl);
            }

            var handlerPath = HostContext.Config.ServiceStackHandlerFactoryPath;

            if (handlerPath != null)
            {
                var pos = httpReq.AbsoluteUri.IndexOf(handlerPath, StringComparison.InvariantCultureIgnoreCase);
                if (pos >= 0)
                {
                    baseUrl = httpReq.AbsoluteUri.Substring(0, pos + handlerPath.Length);
                    return(baseUrl);
                }
                return("/" + handlerPath);
            }

            return("/"); //Can't infer Absolute Uri, fallback to root relative path
        }
Пример #6
0
        private IHttpHandler GetHandlerForPathParts(string[] pathParts)
        {
            var pathController = string.Intern(pathParts[0].ToLower());

            if (pathParts.Length == 1)
            {
                if (pathController == "metadata")
                {
                    return(new IndexMetadataHandler());
                }

                return(null);
            }

            var pathAction = string.Intern(pathParts[1].ToLower());

            if (pathAction == "wsdl")
            {
                if (pathController == "soap11")
                {
                    return(new Soap11WsdlMetadataHandler());
                }
                if (pathController == "soap12")
                {
                    return(new Soap12WsdlMetadataHandler());
                }
            }

            if (pathAction != "metadata")
            {
                return(null);
            }

            switch (pathController)
            {
            case "json":
                return(new JsonMetadataHandler());

            case "xml":
                return(new XmlMetadataHandler());

            case "jsv":
                return(new JsvMetadataHandler());

            case "soap11":
                return(new Soap11MetadataHandler());

            case "soap12":
                return(new Soap12MetadataHandler());

            case "types":

                if (HostContext.Config == null ||
                    HostContext.Config.MetadataTypesConfig == null)
                {
                    return(null);
                }

                if (HostContext.Config.MetadataTypesConfig.BaseUrl == null)
                {
                    HostContext.Config.MetadataTypesConfig.BaseUrl = HttpHandlerFactory.GetBaseUrl();
                }

                return(new MetadataTypesHandler {
                    Config = HostContext.Config.MetadataTypesConfig
                });

            case "operations":

                return(new CustomResponseHandler((httpReq, httpRes) =>
                                                 HostContext.AppHost.HasAccessToMetadata(httpReq, httpRes)
                            ? HostContext.Metadata.GetOperationDtos()
                            : null, "Operations"));

            default:
                string contentType;
                if (HostContext.ContentTypes
                    .ContentTypeFormats.TryGetValue(pathController, out contentType))
                {
                    var format = ContentFormat.GetContentFormat(contentType);
                    return(new CustomMetadataHandler(contentType, format));
                }
                break;
            }
            return(null);
        }