예제 #1
0
        /*public static Uri GetUrlRewriter(this HttpRequestBase request)
         * {
         *  return request != null ? GetUrlRewriter(request.Headers, request.Url) : null;
         * }*/

        public static Uri GetUrlRewriter(IHeaderDictionary headers, HttpRequest request)
        {
            if (headers != null)
            {
                var h           = headers[UrlRewriterHeader];
                var rewriterUri = !string.IsNullOrEmpty(h) ? ParseRewriterUrl(h) : null;
                if (request != null && rewriterUri != null)
                {
                    var result = new UriBuilder()
                    {
                        Scheme = rewriterUri.Scheme,
                        Host   = rewriterUri.Host,
                        Port   = rewriterUri.Port
                    };
                    result.Query = request.QueryString.Value;
                    result.Path  = request.Path.Value;
                    return(result.Uri);
                }
            }

            if (request != null && request.Query != null)
            {
                var h           = request.Query[UrlRewriterHeader];
                var rewriterUri = !string.IsNullOrEmpty(h) ? ParseRewriterUrl(h) : null;
                if (rewriterUri != null)
                {
                    var result = new UriBuilder()
                    {
                        Scheme = rewriterUri.Scheme,
                        Host   = rewriterUri.Host,
                        Port   = rewriterUri.Port
                    };
                    result.Query = request.QueryString.Value;
                    result.Path  = request.Path.Value;

                    return(result.Uri);
                }
            }

            return(request.Url());
        }