locked
How to access network id in asp.net 4.0 RRS feed

  • Question

  • User-268378125 posted

    I have created a test web application in .Net framework 4.0 with Default.aspx page. I just want o access network id of user so I wrote following code in default.aspx code behind but getting blank value when I run the application pressing F5:

    string username = Page.User.Identity.Name;

    and in web.config enable the Windows authentication mode:

    <authentication mode="Windows" />

    then I tried following in Console application and I'm able to get my network id:

    Console.WriteLine(Environment.UserName);

    Am I missing any configuration steps in web application.

    Thanks

    Friday, September 30, 2016 12:15 PM

All replies

  • User753101303 posted

    Hi,

    Using Page.User.Identity.Name is correct but it works only if the user is actually authenticated. Make sure to disable anonymous authentication (else the authentication doesn't happen as it is not needed to access the site).

    Don't use Environment.UserName, this is the account under which you can run which is not always the same than the authenticated user (unlike Identity.Name).

    Friday, September 30, 2016 12:25 PM
  • User-268378125 posted

    I have following settings in IIS

    Anonymous Authentication Disabled
    ASP.NET Impersonation Disabled
    Forms Authentication Disabled
    Windows Authentication Enabled

    and following settings in web.config

    <authentication mode="Windows" />
          <!--<authorization>
            <deny users="?"/>
          </authorization>-->

    Now if I browse the website I got Windows Security pop up and ask my windows credentials. I tried with my windows login details but go following message:

    Username: mydomain\mynetworkid
    Password: my windows password

    HTTP Error 401.1 - Unauthorized

    You do not have permission to view this directory or page using the credentials that you supplied.

    Friday, September 30, 2016 2:22 PM
  • User753101303 posted

    And does your account have read access to the web site files ?

    For this kind of issue the IIS site/forum might be better. For example you have http://www.iis.net/learn/get-started/planning-for-security/secure-content-in-iis-through-file-system-acls

    Friday, September 30, 2016 2:38 PM
  • User-268378125 posted

    I have given full access to following Groups or username for website folder but still not able to login through my Windows login details:
    SYSTEMNETWORK SERVICE
    Administrator(mycomputername\Administrator)
    Users(mycomputername\Users)
    IIS_IUSRS(mucomputername\IIS_IUSRS)
    TrustedInstaller

    but when I did enable only Basic Authentication I am able to login with my windows credentials

    Saturday, October 1, 2016 7:48 PM
  • User-268378125 posted

    Later on I did enable only Windows Authentication and added new binding( for exp: 192.168.1.14 and port 83). I browsed  http://192.168.1.14:83 URL from other computer on same network and able to login with windows credentials.

    Sunday, October 2, 2016 3:19 AM