Asp.net mvc 4 Why is home being required in my url?

Asp.net mvc 4 Why is home being required in my url?,asp.net-mvc-4,Asp.net Mvc 4,I have a route defined routes.MapRoute( name: "NoRightsRoute", url: "norights", defaults: new { controller = "Home", action = "NoRights" } ); and in a check on if the user has rights I redirect them to this route if they don't Response.RedirectToRoute("NoRightsRoute"); the url that it redirects to is https://localhost/norights Home is removed which I would expect since that is assumed by MVC but I get an error "The resource could not be found" if I change the url to h

I have a route defined

routes.MapRoute(
    name: "NoRightsRoute",
    url: "norights",
    defaults: new { controller = "Home", action = "NoRights" }
);

and in a check on if the user has rights I redirect them to this route if they don't

Response.RedirectToRoute("NoRightsRoute");

the url that it redirects to is

https://localhost/norights

Home is removed which I would expect since that is assumed by MVC but I get an error

"The resource could not be found"

if I change the url to

https://localhost/Home/norights

the page loads correctly. Why is "Home" being required in my url? Is there some way to have "Home" included in the url so that the redirect works or get the page to load as it should when assumed?


#1

You may try to remove the default, and hard code Home in url.

routes.MapRoute(
    name: "NoRightsRoute",
    url: "Home/norights",
);

But check that other links /redirections are not impacted !


#2

Is there another route defined before that?

#3

yes there are 3-4 other routes on that page. could they be conflicting?

#4

the first option put the source controller in the url. The second option puts Home into the URL and the redirect now works. thank you :)

#5

@MattBodily just check that other routes / links are not impacted also !

#6

thank you for the warning. Always good to be aware, just ran through other pages and everything is working correctly. thank you again