我将解决方案从VS2010迁移到VS2013后,出现InvalidCastException。无法转换类型为'System.Web.Hosting.SimpleWorkerRequest'的对象以键入'System.Web.Hosting.IIS7WorkerRequest'
在VS2010一切正常,同样的代码给出VS2013以下错误:
类型的异常则“”发生在 System.Web.dll中,但在用户代码中没有处理
其他信息:无法转换 类型的对象“System.Web.Hosting.SimpleWorkerRequest”到类型 “System.Web.Hosting.IIS7WorkerRequest”。
我不知道该怎么办,在互联网上找不到任何相关内容。
误差在下面的代码段发生在第5行:
public static void AuthenticateUser(String UserName, Int32 Minutes = 30, Boolean IsPersistent = true)
{
FormsAuthenticationTicket _ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(Minutes), IsPersistent, String.Empty);
FormsIdentity _id = new FormsIdentity(_ticket);
var _roles = Roles.GetRolesForUser(UserName);
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(_id, _roles);
}
错误发生在一段代码中,演员不是由我完成的。我编辑了我的问题。 –
是AuthenticateUser一个用户定义的方法吗?尝试打破Roles.GetRolesForUser调用来查看错误是否真的在那里发生。如果是这样,是所有用户还是只有一个?基本的问题是某处某处正在尝试这种非法演员。导致这种非法转换的假设必须经过检查,然后才能解决。 – Marisa
AuthenticateUser是用户定义的方法。我已经打破了Roles.GetRolesForUser,错误发生在这里。 –