问题
I want to have many projects(like 20) in one ASP.NET solution. All projects would have their own databases, models, views and controllers. Can you tell me how I can do that? And how the urls would be? If there is one project in the solution it is like this :
localhost:12345/Controller/View
When there are more projects, would the correct configuration like this ? :
localhost:12345/ProjectName/Controller/View
One more thing, I am planning to use Identity 2.0 Framework. Is it possible for a user to be logged in in all projects when he logs in once? Thanks.
回答1:
Can you tell me how I can do that? And how the urls would be?
You can have 'n' number of projects in your solution. You need to handle it using the RouteConfig.cs
where if you have three projects as 'Project1', 'Project2' and 'Project3'. Then your respective route config would be something like below:
routes.MapRoute(
name: "Default_1",
url: "Project1/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Similarly,
routes.MapRoute(
name: "Default_2",
url: "Project2/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Is it possible for a user to be logged in in all projects when he logs in once?
Yes, it is definetly possible. But ASP.NET Identity out of the box does not support multiple applications.Having said that it's the developers task to achieve it thru Single Sign On
Link : How to implement it
Hope it helps!
回答2:
You can have as many projects in a single solution you want. Just right click on the solution in the Project Explorer window and select Add New Project. In the properties of each project, set its root directory to be /applicationname.
You would need to look into the details of oAuth to implement a single sign on scheme, and I can't really help you there, but that is the whole purpose behind that implementation, so it is definitely possible.
来源:https://stackoverflow.com/questions/29791281/having-separate-projects-in-one-asp-net-mvc-5-solution