3

When I have this route setup I can trigger any controllerName/actionName url because I do not need a start url/page.

I do not run a web api because I want to use razor for my views.

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapMvcAttributeRoutes();
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "*", action = "*", id = UrlParameter.Optional }
        );

    }

but when I start my project and run my site I see the base url in the browser: http://localhost:62127/

giving me a 404 error.

How can I configure my project to return a 403 error which is IIS typically giving me? When directory browsing is disabled?

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
Pascal
  • 12,265
  • 25
  • 103
  • 195
  • Any particular reason you want to return a 403? Technically, a 404 is correct here. – user247702 Feb 08 '16 at 20:55
  • Yes technically it would be correct. I just want to learn. :-) – Pascal Feb 08 '16 at 21:14
  • 1
    One possibility is to create a controller/action that simply returns a [`HttpStatusCodeResult`](https://msdn.microsoft.com/en-us/library/system.web.mvc.httpstatuscoderesult.aspx). You could also [create an ActionFilter](http://stackoverflow.com/questions/11726848/asp-net-mvc-4-intercept-all-incoming-requests) or intercept the request in `Application_BeginRequest`. – user247702 Feb 08 '16 at 21:16
  • Is there not a elegant web.config setting without touching the code? – Pascal Feb 08 '16 at 21:17
  • Perhaps, but I don't know any by heart. – user247702 Feb 08 '16 at 21:18
  • You can use the but that wont change the status code, I guess you could have a controller action which returned a 403 status code in the response by setting Response.StatusCode = 403; – Cookie Mar 16 '16 at 15:30

0 Answers0