How can I do this: I have on page named ‘Schedule’ and it can be accessed through 2 differente ways:
URL 1- www.bla.com/Admin/Schedule URL 2- www.bla.com/Schedule
‘URL 1’ will be accessed by users with Admin previlegies and this View will show some Admin stuff, and users must be LoggedOn.
In the otherhand, ‘URL 2’ will be accessed by users NOT LoggedOn and it will NOT show the admin stuff.
But, they are the same page, just with some differences depending on user’s access.
I already have AdminController and I intend to put this ‘Schedule’ View as part of this controller. As result, I know if I type ‘URL 1’ it will work. But, if I type ‘URL 2’? Will I have to create a ‘ScheduleController’ just to handle this?
I wonder if there is a way to resolve this by Global.asax, configuring the routing… I don’t know…
Thanks!!!
You can map the /Schedule route to the /Admin/Schedule action from the Global.asax.cs like this:
This will solve your immediate problem of wanting two separate routes resulting in the same action/view.
However, this will not solve your scenario properly. The main issue is that the identity of the logged on user is orthogonal to the route the request takes. In other words, you can’t force the admin user to always hit the /Admin/Schedule route, they could just as well hit the /Schedule route and still would expect the same end result. Not only that, but doing it this way will prevent you from using the [Authorize] attribute on the Admin controller or the action to force the user to login and will have to implement custom logic checking which route the action was hit through and decide whether you want to force login or let the user through.
Thus, you have to make a decision:
In all three cases, you can still have the rule above pointing to the appropriate controller, if you want to have also the shortest /Schedule route.