How to Decarote Url in asp.net MVC , so that Url identifies Which UserType is begin accessed

115 Views Asked by At

I am currently working on an asp.net mvc application with three UserTypes. 1) Admin 2)School 3)Parent

I want to Decorate the Url With 3 parts ,

like if it is admin then ->     Admin/{Controller}/{Action}/{id}
if Shcool ->     School/{Controller}/{Action}/{id} 
if Parent - >     Parent/{Controller}/{Action}/{id}

I tried to modify the routeconfig.cs as

 routes.MapRoute(
    name: "Default",
    url: "School/{controller}/{action}/{id}",
    defaults: new { controller = "EstablishmentLogin", action = "Login", id = UrlParameter.Optional    });

It worked , but the problem is where ever i have used ajax calls , i need to modify the url from [{Controller}/{Action}/{id}] to [School/{controller}/{Action}/{id}].

It will be time consuming to find out all the ajax calls and modify the urls. Please suggest me if there is any alternative for this issue.

Also I want to Organize the folders Physically as

1)Admin -> Controllers 
-> View
-> models 

2)School - > Controllers
- > Views 
-> Models`enter code here

3)Parent - > Controllers
- > Views 
- > Models 
How can i acheive this ?
1

There are 1 best solutions below

0
On

Set them up as Areas. Right click on your project -> Add -> Area. It'll create a folder structure exactly like what you laid out in your question. The area will also have its own version of RouteConfig.cs named [AreaName]AreaRegistration.cs. It's like a mini MVC site within your main project. If you need to create a link between areas or between the main site and an area you construct it like...Url.Action("Action", "Controller", new { area = "AreaName" });