views:

3313

answers:

3

Hi i am using "System.Security.Principal.WindowsIdentity.GetCurrent().Name " to get the client machine username,with windows authentication in my web.config. My question is that whether this code works when i put the page in intranet.Did i able to get the user name who ever logged in my page by using this...b'coz i need to create a session of the username and proceeds further.

This the Code I am using

void Authenticate() { string strLogin = null;

    try
    {
        strLogin = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        Session.Add("Login", strLogin);
        //Label1.Text = strLogin;
        //Label2.Text = System.Environment.UserName;


    }
    catch (Exception ex)
    {
        Response.Write(strLogin);
        Response.Write("<br/>handled:" + ex.Message.ToString());
        Response.End();
    }
    finally
    {
        GC.Collect();
    }
}
A: 

If your users logon on your website, the you can get the name of the current user with Page.User.Identity.Name.

eKek0
A: 

Yes. and it also works in Page.User.Identity.Name

Chad Grant
+2  A: 

You will need to configure the application to impersonate the Windows user who is accessing it by adding the following element after the authentication element in the Web.Config:

<identity impersonate="true"/>

If you do not set impersonate to true then the worker process runs as the Network Service or ASPNET account, depending on your version of IIS.

Phaedrus
thanks for the replies.How could i test this windows authentication in local machine as i dont have intranet,and systems under domain.
Xyz