1

After reading this : .NET MVC-4 routing with custom slugs

I was able to implement the solution into my project :

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
).RouteHandler = new SlugRouteHandler(); ;

and made a little change on the SlugRouteHandler class :

public class SlugRouteHandler : MvcRouteHandler
{
    protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var url = requestContext.HttpContext.Request.Path.TrimStart('/');


        if (!string.IsNullOrEmpty(url))
        {
            if (url.Contains("_escaped_fragment_"))
                requestContext.HttpContext.Response.StatusCode = 401;
            else
                requestContext.HttpContext.Response.StatusCode = 404;

            FillRequest("Error","Index", requestContext);
        }

        return base.GetHttpHandler(requestContext);
    }
    private static void FillRequest(string controller, string action, RequestContext requestContext)
    {
        if (requestContext == null)
        {
            throw new ArgumentNullException("requestContext");
        }

        requestContext.RouteData.Values["controller"] = controller;
        requestContext.RouteData.Values["action"] = action;
    }
}

This is the result on my local host, perfect :

enter image description here

but after publishing the project to the host, it doesn't work as I expected :

enter image description here

Is there any chance this is because of the server's configurations?

Community
  • 1
  • 1
NeedAnswers
  • 1,411
  • 3
  • 19
  • 43

0 Answers0