问题描述
使用的WebForms在VS2013在C#中,同时为ASP .NET 4,我正在实施已经通过了我的所有应用程序中使用自定义的安全对象。从VS2010到VS2013的提升,我来到这个错误窃听了我这么多......
While developing in C# for ASP .net 4 in VS2013 using WebForms, I was implementing a custom security object that has been used through out of all my applications. With the upgrading from VS2010 to VS2013, I came to this error that bugged me so much....
无法投类型的对象
System.Security.Principal.WindowsIdentity到类型
CustomSecurity.BusinessObject.EmployeeIdentity
和为code的位置如下:
And the code location as follows:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//This is where it fails
EmployeeIdentity employeeIdentity = (EmployeeIdentity)HttpContext.Current.User.Identity;
}
}
code的这条线在VS2010工作,但在VS2013没有工作。在code编译,但在运行时给了我这个错误。
This line of code worked in VS2010 but didn't work in VS2013. The code compiles but gives me this error during run time.
事情到目前为止,我曾尝试:
- 将转换为CustomSecurity.BusinessObject.EmployeeIdentity .NET 4的组装
- 改变code使用Page.User,我仍然得到同样的错误
- 阅读StackOverflow的其他职位,在找到答案没有运气....
我的问题:
什么是可以解决我的问题其他建议?
My Question:What are other suggestions that may resolve my issue?
推荐答案
所以,从VS2010转换code到VS2013,我需要改变是添加以下到Web.config:
So from converting the code from VS2010 to VS2013, the changes I need was to add the following to the Web.config:
<system.webServer>
<modules>
<!-- Add a Custom Authentication module THIS NEEDS TO BE ADDED FOR IIS8 + .NET 4 -->
<add name="DHAAuthenticationModule" type=" DHA.CustomSecurity.BusinessObject.DHAAuthenticationModule, DHA.CustomSecurity.BusinessObject"/>
</modules>
</system.webServer>
我假设的原因是是Web服务器需要了解对象的定义以及....
这个固定我的错误,我遇到过。这真的很特殊,我猜。
The reason I am assuming is be the webServer needs to understand object definitions as well.... This fixed my error that I encountered. It was really specific I guess.
在这个有什么想法?
这篇关于无法转换类型'System.Security.Principal.WindowsIdentity'的对象,以自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!