Example #1
0
 public Response AsRedirect(string location, RedirectResponse.RedirectType type = RedirectResponse.RedirectType.SeeOther)
 {
     return(new RedirectResponse(this.Context.ToFullPath(location), type));
 }
Example #2
0
        //public static Response AsError(this IResponseFormatter formatter, IViewFactory factory, Exception exception, string title = null)
        //{
        //    var model = new ErrorResponseModel() {Description = exception.Message, Title = title};
        //    return AsError(formatter, factory, model);
        //}

        //public static Response AsError(this IResponseFormatter formatter, IViewFactory factory, ErrorResponseModel responseModel)
        //{
        //    var viewContext = new ViewLocationContext { Context = formatter.Context };
        //    var response = factory.RenderView("error_page", responseModel, viewContext);
        //    response.StatusCode = HttpStatusCode.InternalServerError;
        //    return response;
        //}

        public static Response AsRedirectLocalized(this IResponseFormatter formatter, string location, RedirectResponse.RedirectType type = RedirectResponse.RedirectType.SeeOther)
        {
            var currentCulture = formatter.Context.Culture;

            if (string.IsNullOrWhiteSpace(location) || currentCulture == null)
            {
                return(formatter.AsRedirect(location, type));
            }

            if (currentCulture.Name.StartsWith("en") || currentCulture.Name.Equals("en"))
            {
                return(formatter.AsRedirect(location, type));
            }

            string currName = currentCulture.Name.Length > 2 ? currentCulture.Name.Substring(0, 2) : currentCulture.Name;

            if (location.StartsWith("/"))
            {
                var localizedPath = string.Concat("/", currName, location);
                return(formatter.AsRedirect(localizedPath, type));
            }

            if (location.StartsWith("~/"))
            {
                var localizedPath = string.Concat("~/", currName, location.Substring(1));
                return(formatter.AsRedirect(localizedPath, type));
            }

            return(formatter.AsRedirect(location, type));
        }
Example #3
0
 /// <summary>
 /// Returns a redirect response to the agent.
 /// </summary>
 /// <param name="formatter">The formatter.</param>
 /// <param name="location">The location to redirect to.</param>
 /// <param name="type">The redirect type. See <see cref="RedirectResponse.RedirectType"/>.</param>
 public static Response AsRedirect(this IResponseFormatter formatter, string location, RedirectResponse.RedirectType type = RedirectResponse.RedirectType.SeeOther)
 {
     return(new RedirectResponse(formatter.Context.ToFullPath(location), type));
 }