2011-11-14 20 views
2

MVCを使用して作成した2つのWebサイトに同時にアクセスしようとしています。私がm logged In in one, I canにアクセスすると、もう一方にアクセスします。次のように修正するにはどうすればよいですか?同時に2つのWebサイト(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:値Nullにすることはできません

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.

例外の詳細は、両方のアプリを同じマシンキーを挿入した後4.0.30319.237


新しいエラーメッセージ。 パラメータ名:値

ソースエラー:

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

同じ認証クッキーが使用されているようです。 – leppie

+0

@leppieどうすれば修正できますか? – learning

+0

あなたはSoftionと私が与えたソリューションを試しましたか?どんなフィードバック? –

答えて

-1

質問にお返事いただきありがとうございました。実際彼らはすべて役に立ちました。私はマシンキーをwenconfigに追加するだけで問題は解決しました。フォーム名もそこになければなりませんでした。テムフォーム名がなくても、マシンキーでさえも役に立たなかった

+0

を持っていますが、 'tをそれはdoen't作品:' <のmachineKey validationKey = "2D22CD7A956C67564FF77D740FF1377A71A3F5AEA01D8455CC53FA76F90DFF46D721A435FE7CCCF02FFFD7CA51816A69F1E86799E09F8AF698DCB56B387497F3" decryptionKey = "9B2E487F2BA9785B0D427A2D911FC911C04F4AD48062D0AE1EC0C424E4D752DF" 検証= "SHA1" 解読= "AES" /> '**フォーム名**はどういう意味ですか?よろしく。 –

+0

問題は、クライアントがリモートデスクトップを使用している場合です。どうして?たぶん、いくつかのセキュリティ問題が更新されますか?よろしく。 –

+0

「フォーム名」は何ですか? –

2

私は推測しているあなたは、フォーム認証を使用していますか?たぶん、両方のクッキーは、同じドメインを使用して異なるマシンキーを使用して作成されることがあります。

したがって、サイトAがクッキーを作成して(ログインしていない)サイトBに行くと、サイトBはドメインを調べて、このユーザーがログインしていると言ってデータを復号化できますクッキーはMACHINE KEY Aを使用して暗号化されています。

マイ2C :)

+0

私はGor Authが何であるか分かりません。あなたは私にリンクを与えることができますか?クッキーのドメインを選択し、両方のサイトが異なるドメインを持っていることを確認する設定領域があるはずです –

+0

私はフォーム自動化を使用しています。 – learning

+0

「認証」ノードの下のweb.configに「フォーム」ノードが表示されます。そこにはdomain = "DOMAINNAME"属性を追加するだけです。両方のサイトでそれらが異なることを確認してください。 –

1

私はそれを推測:あなたのウェブサイトが2つの異なる自動生成のmachineKeyを使用

1)。 MachineKeyは、フォーム認証Cookie、ハッシュパスワード、...の内容をエンコード/デコードするために使用される定数キーです。

2)両方のアプリケーションで同じapplicationNameを使用しました。

3)ベータウェブサイトとプロダクションウェブサイトを同じマシンにセットアップしようとしていると思います。

+0

私はサイトからオンラインでマシンキーを生成し、両方のアプリケーションに挿入しました。今私は別のエラーが発生しています:[ArgumentNullException:値をnullにすることはできません。 パラメータ名:値] System.Web.Caching.CacheEntry..ctor(文字列のキー、オブジェクトの値が、可能CacheDependency依存性、CacheItemRemovedCallback onRemovedHandler、DateTimeのutcAbsoluteExpiration、TimeSpanのslidingExpiration、CacheItemPriorityの優先順位、ブールisPublic)8942559 に編集した部分を参照してください。完全なエラーメッセージが表示される – learning

+0

アプリケーション名はどういう意味ですか?アセンブリ名またはソリューション名ですか?ソリューション名は異なりますがアセンブリ名はありません – learning

+0

ベータウェブサイトと本番ウェブサイトは同じマシンにありません – learning

0

これをチェックするlinkそれはどういうわけか、+1を与えたanswerに関連しています。

thisは、2つのアプリケーションのいずれかの別のキーを生成するのに便利です。

+0

私は私のweb.configファイルでのmachineKeyを追加したデフォルトのページ – learning

関連する問題