简体   繁体   中英

Error on start website in Server (IIS 7)

I have an aplication Web Forms ASP.NET Framework 4.0 with c#. I published it and create in IIS (Web Server). When I access this website, an error occur.

My app pool already set Framework 4.0!

Error:

Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.

In my home.aspx, have an label with user name of 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;
}

I use System.DirectoryServices.AccountManagement;

I can't use this authentication in IIS? In my localhost, work correctly

Try this:

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;
   }
}

Also make sure you have windows authentication mode enabled and your app pool is running 4.0 integrated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM