2016-12-29 122 views
0

我必須部署到IIS Web服務器的兩個Web應用程序,他們兩人都是 在同一IIS服務器上的同一個應用程序池 ,但單獨的應用程序池。他們都使用Windows AD組進行身份驗證,因此將SiteA用戶添加到SiteA AD Group,並將SiteB用戶添加到SiteB AD Group,並允許他們訪問各自的站點。這些網站沒有任何關聯,並且完全相互獨立。在全球的的Application_Start,他們有這樣的:部署C#MVC的Web應用程序運行時錯誤

站點A

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); 

    } 

網站B

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); 

    } 

只有我展示這個原因是因爲我懷疑這是在哪裏問題在於,但事實上我不知道。

的問題是,這兩個網站的工作,因爲他們應該獨立。因爲我在兩個AD組中都可以開始任何一個並獲得訪問權限。問題是,當我在我的瀏覽器一個網站打開,然後打開其他的,我得到一個運行時錯誤:
運行時錯誤

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.

出現這種情況,無論我先打開哪個網站,所以如果我打開站點A ,它會打開罰款,然後如果我在另一個選項卡中打開SiteB,它將產生SiteB的錯誤。反之亦然,如果我先打開SiteB,然後打開SiteA,它將爲SiteA產生該錯誤。我可以單獨打開一個,但必須關閉瀏覽器和瀏覽器的所有實例,才能打開其他瀏覽器。所以我認爲這與緩存無關,但我無法確定。當應用程序啓動時,在全局的Application_PostAuthenticateRequest方法中,標識用戶,並且如果必要的AD組的一部分,它們的詳細信息將被添加到Context.User中。它在兩個應用程序中的工作方式完全相同。任何人都知道爲什麼會發生這種情況?是否這兩個應用程序試圖保存到Context.User時,都是同時啓動?

編輯:

忘了補充,當我在開發環境中同時運行兩個,他們都工作。

EDIT2:

安徒生皮門特爾的建議,我檢查在事件查看器的應用程序日誌,並有以下錯誤:

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)

所以糾正我,如果我錯了,但似乎SiteB正在嘗試解密已由SiteA加密的身份驗證Cookie,因此具有不同的密鑰,這就是它正在崩潰的地方。是對的嗎?

+1

檢查事件查看器中的應用程序日誌以獲取有關該異常的更多信息。 –

+0

是否這樣做,請參閱上面的修改。 – necrofish666

+0

您是否檢查過[this](http://stackoverflow.com/questions/25857577/error-occurred-during-a-cryptographic-operation-when-decrypting-forms-cookie)? –

回答

1

您可能會遺漏關於web.config的機器密鑰信息,該密鑰信息用作對稱密鑰來執行加密和解密。

要生成IIS中的關鍵:在MSDN

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

更多信息。

+0

我剛剛添加了到這兩個應用程序的web.config,根據您之前提供的鏈接的建議,它沒有修復問題。你認爲我還應該嘗試生成密鑰選項嗎?這是不是會搞砸這些應用程序?他們現在都部署和生活了,如果辦公室在事情出錯的時候解決問題,我是唯一一個,而且我只是一個初級開發人員,你可以告訴我,我不是100%我正在做。試圖解決一個小問題... – necrofish666

0

對於這個工作,你必須使用兩個單獨的應用程序池。

SiteB中不允許站點A AD用戶條目(這是當您第一次使用站點A你的身份變),反之亦然。這可以通過使用單獨的應用程序池來避免:然後您在兩個站點上擁有不同的身份。

+0

我會試試這個,謝謝。我會讓你知道它是否有效。 – necrofish666

+0

好吧,我認爲我在最初的帖子中錯了。我剛剛檢查過,看起來他們在單獨的應用程序池中。有關應用程序日誌中的錯誤,請參閱上面的編輯,我認爲這是問題所在。對不起,困惑。 – necrofish666

相關問題