0

I have two web applications deployed to IIS web server, both of them are on the same application pool on the same IIS server, but separate application pools. They both use Windows AD groups for authentication, so SiteA users are added to SiteA AD Group, and SiteB users are added to SiteB AD Group, and they are allowed access to their respective sites. The sites are in no way connected, and are entirely independent of one another. In the global, the Application_Start, they have this:

SiteA

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        log4net.Config.XmlConfigurator.Configure();
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        var rolesDictionary = ((SiteAMembershipProvider)(Membership.Provider)).InitialisePermissionDictionary();
        HttpRuntime.Cache.Insert(
            /* key */                "RolesDictionary",
            /* value */              rolesDictionary,
            /* dependencies */       null,
            /* absoluteExpiration */ Cache.NoAbsoluteExpiration,
            /* slidingExpiration */  Cache.NoSlidingExpiration,
            /* priority */           CacheItemPriority.NotRemovable,
            /* onRemoveCallback */   null);

    }

SiteB

protected void Application_Start()
    {
        log4net.Config.XmlConfigurator.Configure();
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        var rolesDictionary = ((SiteBMembershipProvider)(Membership.Provider)).InitialisePermissionDictionary();
        HttpRuntime.Cache.Insert(
            /* key */                "RolesDictionary",
            /* value */              rolesDictionary,
            /* dependencies */       null,
            /* absoluteExpiration */ Cache.NoAbsoluteExpiration,
            /* slidingExpiration */  Cache.NoSlidingExpiration,
            /* priority */           CacheItemPriority.NotRemovable,
            /* onRemoveCallback */   null);

    }

Only reason I'm showing this is because I suspect this is where the problem lies, but in truth I have no idea.

The problem is, both of these sites work as they should individually. I can start either one and get access since I am in both AD groups. The problem is when I have one site open in my browser, then open the other, I get a runtime error:
Runtime Error

Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.

This happens no matter which site I open first, so if I open SiteA, it will open fine, then if I open SiteB in another tab, it will produce the error for SiteB. And vice-versa, if I open SiteB first, then open SiteA, it will produce that error for SiteA. I can open either one individually, but have to close the browser, and all instances of the browser, to be able to open the other. So I think it is something to do with whatever it's caching, but I can't be sure. When the application starts, in the Application_PostAuthenticateRequest method in the global, the user is identified, and if part of the necessary AD group, their details are added to Context.User. It works the exact same way in both apps. Anybody got any idea why this may be happening? Is it to do with both applications trying to save to Context.User when both are started simultaneously?

Edit:

Forgot to add, when I run the both at the same time in the dev environment, they both work.

Edit2:

On the advice of Anderson Pimentel, I checked the Application logs in Event viewer, and there is the following error:

Exception information: Exception type: CryptographicException Exception message: Error occurred during a cryptographic operation. at System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func, Byte[] input) at System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) at AuditTracker.MvcApplication.Application_PostAuthenticateRequest(Object sender, EventArgs args) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

So correct me if I'm wrong, but it seems like SiteB is trying to decrypt the authentication cookie, which has already been encrypted by SiteA, and so has a different key, and that's where it's falling over. Is that right?

necrofish666
  • 75
  • 1
  • 7
  • 24

2 Answers2

1

You are probably missing machine key information on web.config, which is used as a symmetric key to do the encryption and decryption.

To generate the key in IIS:

Go to your application -> Machine Keys -> Generate Keys

More info on MSDN.

Anderson Pimentel
  • 5,086
  • 2
  • 32
  • 54
  • I just added to the web.config of both applications, based on the advice of the link you previously provided, it didn't fix the problem. Do you think I should still try the Generate Keys option? It's not gonna mess up either of these apps is it? They're both deployed and live right now, and I'm the only one if the office to fix things if anything goes wrong, and I'm only a junior dev, as you can tell, I'm not 100% on what I'm doing. Just trying to fix a small problem... – necrofish666 Dec 29 '16 at 12:02
0

For this to work you must use two separate application pools.

SiteB does not allow entry for SiteA AD users (which is what your Identity becomes when you use SiteA first), and vice versa. This can be avoided by using separate application pools: then you have different identities on both sites.

Peter B
  • 22,460
  • 5
  • 32
  • 69
  • I'll give this a try, thanks. I'll let you know if it works. – necrofish666 Dec 29 '16 at 11:37
  • OK, I think I was wrong in my initial posting. I've just checked, and it looks like they're on separate application pools. See the edit above for the error in the application log, I think that's where the problem lies. Sorry for the confustion. – necrofish666 Dec 29 '16 at 11:41