1

I have read this thread SimpleMembership - anyone made it n-tier friendly? but it speaks directly about making the simplemembership n-tier friendly. Even thought that is the next likely progression of my line of questioning, I have yet to bypass my current hurdle.

I have multiple MVC 4 applications which all use the same database tables for logging in and I want to maintain the log in connection between applications. I have modified the SimpleMembership (controllers, views, and css) and associated database tables (I have added several tables which define allowed applications and roles within those applications), all that is left to do is make a single log in apply over all of the applications. Is this something that anyone has done or knows how to do? Eventually, I would like to move the log in portion of these applications out to it's own project, since changing the css, html, and controllers has to occur in each of the applications every time something is edited.

If anyone has any other suggestions that may work better I am all ears!

Community
  • 1
  • 1
Joel Priddy
  • 481
  • 3
  • 13

2 Answers2

0

I seem to remember that all is needed is to use the same machineKey configuration per application in your <system.web> section of your web.config per application:

<machineKey validationKey="valkey" decryptionKey="deckey" decryption="3DES" validation="SHA1" />
Cameron Tinker
  • 9,634
  • 10
  • 46
  • 85
  • That is interesting, but can you explain why using the same machineKey will allow for the application scope to be shared? – Travis J Sep 30 '13 at 17:37
  • I'm not an expert with SimpleMembership, but since it aims to replace ASP.NET Membership, this should in theory work. I may be completely off base with this though. I thought the question said ASP.NET membership. I used this technique when running multiple applications (YAF.NET, BlogEngine.NET, and a custom application) for unified authentication between each application. – Cameron Tinker Sep 30 '13 at 17:40
  • I'm in the same boat as Travis J. I apologize if I am missing something rudimentary to web development. – Joel Priddy Sep 30 '13 at 17:45
  • @JoelPriddy Not a problem. I believe I may have misread the question initially. – Cameron Tinker Sep 30 '13 at 17:48
  • I have figured out a way, using the machine key, to accomplish this...sort of. I had originally intended to create a "Log In/Log Out" application which would contain all of the controllers, views, and models for this. What I ended up doing is creating a portal which contains links to all of the other applications, as well as the log in and user maintenance stuff. In the other applications, I just have the log in, log out, and user management links redirect to the portal. – Joel Priddy Mar 07 '14 at 15:28
0

I am not entirely sure what the best practice is for this, but here is an idea that comes to mind.

A major constraint will be to be able to share the application pool and the sessions for these users.

One way (again, I am not sure what the best practice is) would be to have all of these applications setup from one place. An entry tier if you will. This will only have a global.asax definition for starting the applications. Each application will start from one place, allowing them to all share the same scope. This can be accomplished with a few steps in your global.asax file.

Right click on global.asax and click show markup

<%@ Application Codebehind="Global.asax.cs" Inherits="appNamespace.ApplicationModerator" Language="C#" %>

Inside of global.asax.cs

public class ApplicationModerator : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        new namespace1.TierApplication1();
        new namespace2.TierApplication2();
        new namespace3.TierApplication3();
    }
}

TierApplication1 (they will all be different, but have similar features)

public class TierApplication1 
{
    public TierApplication1 ()
    {
        AreaRegistration.RegisterAllAreas();

        Database.SetInitializer<DbContext>(null);

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("favicon.ico");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }, // Parameter defaults
        );
    }
}
Travis J
  • 81,153
  • 41
  • 202
  • 273
  • So, what you are talking about here is a completely new "application" which would be a launchpad for all of the other applications? This is where the "TierApplication" comes from, with the tier number being 1 to n? – Joel Priddy Sep 30 '13 at 18:15
  • @JoelPriddy - In essence, yes. I know it is a little extreme, but this was all I could think of. – Travis J Sep 30 '13 at 18:15
  • I appreciate the effort and I am sure that this would likely give me the result I am looking for. I'll give it a try and see if it will work with my specific scenario. – Joel Priddy Sep 30 '13 at 18:21