Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having separate projects in one ASP.NET MVC 5 solution

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.

like image 264
jason Avatar asked Apr 22 '15 08:04

jason


People also ask

Should you split your ASP NET MVC project into multiple projects?

It shouldn't! That's why it's designed in a modular way. In most web applications out there, we version and deploy all these assemblies (Web, BLL and DAL) together. So, separating a project into 3 projects does not add any values.

Can we use two multiple models with a single view?

You can use multiple models in a single view by creating a common model for all the models that are to be used in a single view. To achieve this, refer to the following steps. First, create a new model (common for all models) and refer all other models that are to be used in the same view.

How do you share code between projects solutions in Visual Studio?

To add a Shared Project to your existing solution, right-click on the Solution and choose "Add Project", and then select "Shared Project" from the Visual C# tab: You'll see the Shared Project appear within the Solution Explorer and from this point, you can begin adding any types of files that you want to use to it.

Can we define multiple routes for single action?

You can also write multiple routes onthe same action or controller. For example if you want to call Contact action method with /Home/contact url just write the [Route("home/contact")] on action method.


1 Answers

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!

like image 144
Shubh Avatar answered Oct 12 '22 23:10

Shubh