2011-11-14 22 views
2

我試圖訪問兩個網站同時使用MVC構建。如果我m logged In in one, I can t訪問其他。我如何糾正以下內容?訪問兩個網站(使用mvc構建)同時給出錯誤消息

我有錯誤消息:

Unable to validate data. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

異常詳細信息:System.Web.HttpException:無法驗證數據。

源錯誤:

在當前web請求的執行過程中生成未處理的異常。關於異常的來源和位置的信息可以使用下面的異常堆棧跟蹤來標識。

堆棧跟蹤:

[HttpException (0x80004005): Unable to validate data.]
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData) +4956871
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType) +155 System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +283
MvcUI.MvcApplication.FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs args) in C:\Hg\MyProject\Code\MvcUI\Global.asax.cs:40
System.Web.Security.FormsAuthenticationModule.OnAuthenticate(FormsAuthenticationEventArgs e) +11497690
System.Web.Security.FormsAuthenticationModule.OnEnter(Object source, EventArgs eventArgs) +88
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270


版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本信息:System.ArgumentNullException:值不能爲空4.0.30319.237


新插入同一臺機器鍵這兩個應用

Value cannot be null. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

異常詳細信息後,錯誤信息。 參數名:價值

源錯誤:

Line 71: { Line 72: user = myProject.API.User.Load(userName); Line 73: HttpContext.Current.Cache.Add(key, user, null, System.Web.Caching.Cache.NoAbsoluteExpiration, Line 74: new TimeSpan(0, 2, 0), System.Web.Caching.CacheItemPriority.Default, null); Line 75: }

[ArgumentNullException: Value cannot be null. Parameter name: value] System.Web.Caching.CacheEntry..ctor(String key, Object value, CacheDependency dependency, CacheItemRemovedCallback onRemovedHandler, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, Boolean isPublic) +8942559 System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic, String key, Object value, CacheDependency dependencies, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace) +93 System.Web.Caching.Cache.Add(String key, Object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback) +81 MvcUI.MvcApplication.GetUserFromCache(String userName) in C:\Dev\myProject\Code\MvcUI\Global.asax.cs:73 MvcUI.MvcApplication.FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs args) in C:\Dev\myProject\Code\MvcUI\Global.asax.cs:40 System.Web.Security.FormsAuthenticationModule.OnAuthenticate(FormsAuthenticationEventArgs e) +9043237 System.Web.Security.FormsAuthenticationModule.OnEnter(Object source, EventArgs eventArgs) +84 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


的Global.asax.cs

public class MvcApplication : System.Web.HttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); }

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

     routes.MapRoute(
       "Default", // Route name 
       "{controller}/{action}/{id}", // URL with parameters 
       new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
     ); 
    } 

    public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args) 
    { 
     if (FormsAuthentication.CookiesSupported) 
     { 
      if (null != Request.Cookies[FormsAuthentication.FormsCookieName]) 
      { 
       FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value); 
       args.User = new myProject.Web.UI.Classes.UserPrincipal(GetUserFromCache(ticket.Name)); 
      } 
     } 
     else 
      throw new HttpException("Cookieless Forms Authentication is not supported for this application."); 
    } 

    public void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs args) 
    { 
     string username = args.Identity.Name.Substring(args.Identity.Name.IndexOf("\\") + 1); 
     myProject.API.User user = GetUserFromCache(username); 

     if (null == user) 
      throw new HttpException("User could not be found."); 

     args.User = new myProject.Web.UI.Classes.UserPrincipal(user); 
    } 

    protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 

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

    private static myProject.API.User GetUserFromCache(string userName) 
    { 
     string key = "User " + userName; 
     myProject.API.User user = (myProject.API.User)HttpContext.Current.Cache[key]; 
     if (null == user) 
     { 
      user = myProject.API.User.Load(userName); 
      HttpContext.Current.Cache.Add(key, user, null, System.Web.Caching.Cache.NoAbsoluteExpiration, 
        new TimeSpan(0, 2, 0), System.Web.Caching.CacheItemPriority.Default, null); 
     } 

     return user; 
    } 
} 
+0

它看起來正在使用相同的認證cookie。 – leppie

+0

@leppie我該如何糾正? – learning

+0

您是否嘗試過Softion和我提供的解決方案?任何反饋? –

回答

-1

感謝大家試圖回答這個問題。事實上,他們都有幫助。我通過在wenconfig中添加一個機器鍵來解決問題,還有一個表單名稱必須在那裏。沒有te表單名稱,即使機器密鑰沒有用

+0

我加入的machineKey在我的web.config但它doen't工作:'<的machineKey的validationKey = 「2D22CD7A956C67564FF77D740FF1377A71A3F5AEA01D8455CC53FA76F90DFF46D721A435FE7CCCF02FFFD7CA51816A69F1E86799E09F8AF698DCB56B387497F3」 decryptionKey = 「9B2E487F2BA9785B0D427A2D911FC911C04F4AD48062D0AE1EC0C424E4D752DF」 驗證= 「SHA1」 解密= 「AES」 />'你的意思是**表單名稱**。問候 –

+0

好的。問題是當客戶端使用遠程桌面時。爲什麼?也許一些安全問題更新?問候。 –

+0

你能描述什麼是'表單名稱'? –

2

我猜你正在使用窗體身份驗證?也許這兩個cookie都是使用相同的域名創建的,但不同的機器密鑰。

因此,當網站A創建cookie(傢伙登錄),然後您到站點B(未登錄)時,站點B查看域並說這個人登錄可以解密數據,但是因爲Cookie使用MACHINE KEY A進行加密,但失敗。

我2C :)

+0

我不知道什麼Gor Auth。是:)你能給我一個鏈接?應該有一個配置區域,您可以在其中爲Cookie選擇域,確保這兩個站點具有不同的域 –

+0

我正在使用窗體驗證。 – learning

+0

ok然後在web.config的「身份驗證」節點下,您將看到一個「窗體」節點。你可以在那裏添加一個domain =「DOMAINNAME」屬性。確保它們對於這兩個站點都是不同的。 –

1

我猜想:

1)你的網站使用2種不同的自動生成的machineKey。 MachineKey是用於編碼/解碼錶單認證cookie,散列密碼內容的常量鍵......

2)您在這兩個應用程序中都使用了相同的applicationName。

3)我也猜測你正試圖在同一臺機器上設置一個測試網站和一個生產網站。

+0

我從一個網站在線生成機器密鑰並插入到兩個應用程序中。現在我有另一個錯誤:[ArgumentNullException:值不能爲空。 參數名:值] System.Web.Caching.CacheEntry..ctor(String鍵,對象的值,的CacheDependency的依賴,CacheItemRemovedCallback onRemovedHandler,日期時間utcAbsoluteExpiration,時間跨度slidingExpiration,CacheItemPriority優先,布爾isPublic)8942559 請參閱編輯的部分有完整的錯誤信息 – learning

+0

你的意思是應用程序名稱是什麼?它是程序集名稱還是解決方案名稱?解決方案名稱不同,但不是程序集名稱 – learning

+0

測試版網站和生產網站不在同一臺機器上 – learning

0

檢查此link。這與我給+1的answer有某種關係。

您可能會發現this對於爲兩個應用程序之一生成另一個密鑰很有用。

+0

我不有一個默認的頁面 – learning