How to get started with a multi-user MVC application

I searched for examples and found a few, but these are whole large projects. I am looking for some examples of how to get started creating a multi-user MVC application. I think the first part was to decrypt the URL.

In ASP.Net, this is how I did it. I got this from viewing DNN code. How do I do the same in MVC?

Global.asax

private void Application_BeginRequest(Object source, EventArgs e) { HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; string domainName = string.Empty; // domaName now contains 'example' if application.Request was www.example.com domainName = GetDomainName(application.Request); // Using domain, get the info for example from the database object myPortal = // get from database // Save in context for use on other pages context.Items.Add("PortalSettings", myPortal); } 

Then on my base page I get the value from the context.

+4
source share
2 answers
  • Get the domain name. You are on the right track with the DNN code. Just collect around the static variable Request in the debugger; there are all kinds of cool things.
  • You probably need a user store. I use a custom database, but you can use the Microsoft membership provider and the profile provider. Make the domain a property of the user or a property of the organization, and the organization is the property of the user.
  • Save the user's domain in an encrypted cookie. Read the cookie at the beginning of the request and make the user access this org / domain.
  • Create a BaseController that extends Controller, and then all your controllers inherit it. In BaseController, override OnActionExecuting. This is a much easier place for your initial request rigging than Global.asax.cs Begin_request, because you can define the protected members that will be available for each controller.
+2
source

I think an even more reliable means would be to define a user route. In this regular route, you retrieve the domain and put it in the route values.

Then you can have a base controller (as described by Josh) that defines a domain property or the like, and stores that value for convenience (or just retrieves it on demand, anyway).

Pulling it up the route values ​​so you can use this information anywhere in the application along the request path, and not just in the controller, so you will get more reuse from it this way. You can, for example, use it in a custom authorization filter to process user rights in this domain, etc.

+4
source

Source: https://habr.com/ru/post/1301857/


All Articles