locked
System.Security.Principal is giving Netwrok Service RRS feed

  • Question

  • User-186167190 posted

    Hi,

    The code

    System.Security.Principal.

    WindowsIdentity.GetCurrent().Name

    is working fine in my dev machine. If i copy to iis it is returning Network service.

    How to fix it Any Idea?

    I tried by using identitiy impersonate=true and removing anonyms authendication in iis

    Friday, August 9, 2013 11:20 AM

Answers

All replies

  • User289622470 posted

    Hi,

     

      When you run it locally in your login, certinly it will return the current user. but when you deploy it in IIS and try to access it using IIS deployed path, as per my understaing the user will be IUSER and that is the reason why its returning Network Service.

     

    Thanks,

    Friday, August 9, 2013 11:05 PM
  • User-186167190 posted

    Hi Romy Thomas,

    Thanks for the reply.

    I had disabled the anonyms user (IUSER...) in IIS.

    No Luck :)

    Sunday, August 11, 2013 4:09 PM
  • User-742633084 posted

    Hi Sheik,

    What you expect to get from the System.Security.Principal.WindowsIdentiy.GetCurrent() method call?

    The value returned from the method call depends on your security authenticaiton setting and service account configured in IIS server. If you configure IIS application to use Windows authentication and disable anonymous access, this method call will give you the authenticated windows identity from client request. Otherwise, if you enable anonymous access or doesn't use Windows authentication in IIS, then this method call will give you the current windows account used for running the IIS worker process. And you can configure the worker process's execution account by configuring the IIS application pool identity.

    #Application Pool Identities http://www.iis.net/learn/manage/configuring-security/application-pool-identities

    #Specify an Identity for an Application Pool (IIS 7) http://technet.microsoft.com/en-us/library/cc771170(v=WS.10).aspx

    For IIS 6, the configuration will be a bit different:

    #Steps for setting up a custom identity of an IIS 6 application pool http://blogs.msdn.com/b/friis/archive/2010/10/08/steps-for-setting-up-a-custom-identity-of-an-iis-6-application-pool.aspx

    #Configuring Application Pool Identity with IIS 6.0 (IIS 6.0) http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/f05a7c2b-36b0-4b6e-ac7c-662700081f25.mspx?mfr=true

    So if you want to let your ASP.NET web application (IIS worker process) execute under a particular account, you can specify it in the IIS application pool. By default, IIS 6 uses "Network Service" as the default application pool identity.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 12, 2013 11:29 AM
  • User-186167190 posted

    Hi Steven,

    The issue is with identity impersonate in the code behind.

    The Active Directory code is crashing if identity impersonate = true in web.config

    So after that enclosing the AD code with

    using (HostingEnvironment.Impersonate()) {}

    constructs fixed the issue

     

    Thanks for your valuable point

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 13, 2013 8:51 AM