我有一个带有c#的应用程序Web Forms ASP.NET Framework4.0。我将其发布并在IIS (Web服务器)中创建。当我访问此网站时,出现错误。
我的应用程序池已设置为Framework 4.0!
错误:
无法将'System.DirectoryServices.AccountManagement.GroupPrincipal‘类型的对象强制转换为'System.DirectoryServices.AccountManagement.UserPrincipal'.类型
在我的home.aspx中,有一个用户名为windows的标签。
protected void Page_Load(object sender, EventArgs e)
{
string FirstName = UserPrincipal.Current.Surname.ToString();
string LastName = UserPrincipal.Current.GivenName.ToString();
Label1.Text = LastName + " " + FirstName;
}我使用System.DirectoryServices.AccountManagement;
我不能在IIS中使用此身份验证?在我的localhost中,工作正常
发布于 2013-06-27 23:00:45
试试这个:
using System.Web.Hosting;
protected void Page_Load(object sender, EventArgs e)
{
using (HostingEnvironment.Impersonate())
{
string FirstName = UserPrincipal.Current.Surname.ToString();
string LastName = UserPrincipal.Current.GivenName.ToString();
Label1.Text = LastName + " " + FirstName;
}
}此外,请确保您启用了windows身份验证模式,并且您的应用程序池正在运行集成的4.0。
https://stackoverflow.com/questions/17345578
复制相似问题