Пример #1
0
        public void Execute(ICommunicationContext context)
        {
            context.Response.StatusCode = StatusCode;
            switch (RedirectLocation?.IsAbsoluteUri)
            {
            case true:
                context.Response.Headers["Location"] = RedirectLocation.AbsoluteUri;
                break;

            case false when RedirectLocation.ToString().StartsWith("/"):
                var locationWithoutPrecedingSlash = RedirectLocation.ToString().Substring(1);

                context.Response.Headers["Location"] = new Uri(
                    context.ApplicationBaseUri,
                    new Uri(locationWithoutPrecedingSlash, UriKind.Relative)).AbsoluteUri;
                break;

            case false when RedirectLocation.ToString().StartsWith("/") == false:
                context.Response.Headers["Location"] = new Uri(context.Request.Uri, RedirectLocation).AbsoluteUri;

                break;
            }

            OnExecute(context);
        }
Пример #2
0
        public void Execute(ICommunicationContext context)
        {
            context.Response.StatusCode = StatusCode;
            if (RedirectLocation?.IsAbsoluteUri == true)
            {
                context.Response.Headers["Location"] = RedirectLocation.AbsoluteUri;
            }
            else if (RedirectLocation?.IsAbsoluteUri == false && RedirectLocation.ToString().StartsWith("/"))
            {
                var locationWithoutPrecedingSlash = RedirectLocation.ToString().Substring(1);
                context.Response.Headers["Location"] = new Uri(
                    context.ApplicationBaseUri,
                    new Uri(locationWithoutPrecedingSlash, UriKind.Relative)).AbsoluteUri;
            }
            else if (RedirectLocation?.IsAbsoluteUri == false && RedirectLocation.ToString().StartsWith("/") == false)
            {
                context.Response.Headers["Location"] = new Uri(context.Request.Uri, RedirectLocation).AbsoluteUri;
            }


            OnExecute(context);
        }