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;
}
}
同じ認証クッキーが使用されているようです。 – leppie
@leppieどうすれば修正できますか? – learning
あなたはSoftionと私が与えたソリューションを試しましたか?どんなフィードバック? –