How to use a network domain account for an ASP.NET applications which gets the logged on user name from the computer?

1.  In IIS 6 set the following in the application pool for the website.

 

How to use a network domain account for an ASP.NET applications which gets the logged on user name from the computer using?

How to use a network domain account for an ASP.NET applications which gets the logged on user name from the computer using?

 

2. Create the website and assign the above application pool.

3. Add the domain service account to the IIS WPG group on the hosting server.

 

Go to Computer Management > Local Users and Groups >Groups>IIS WPG. Right click on IIS WPG and go to properties. Add domain service account.

Go to Computer Management > Local Users and Groups >Groups>IIS WPG. Right click on IIS WPG and go to properties. Add domain service account.

 

 

4. In the web.config of the application add the following connection string

<add name=Connection Name connectionString=Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=TrueproviderName=System.Data.SqlClient />

5. In the web.config also add identity tag

<system.web> <identity impersonate=true userName=DomainName\DomainAccountName password=DomainAccontPassword/> <system.web>

6. Now in you code if you use the code below it will show the logged on user name

ASP.NET

<div class=”group”>
    <asp:Label ID=”lblSearchUserName” runat=”server”>User Name : </asp:Label> <asp:TextBox ID=”txtSearchUserName” CssClass=”Search” MaxLength=”10″                ValidationGroup=”vgSearchForm” runat=”server” /> (Eg.<%=Replace(Trim(Request.ServerVariables.Item(“LOGON_USER”).ToLower), “domainName\”, “”)%>) <br />
</div>

 

VB.NET

If (Not String.IsNullOrEmpty(Request.ServerVariables.Item(“LOGON_USER”))) Then Dim LogonUserName As String = Trim(Request.ServerVariables.Item(“LOGON_USER”).ToLower)

 ~~

 ~~

 Else             
             Response.Redirect(“Resources/Error/LogOnNameError.htm”)
End If ‘LOGON_USER

Reference:

http://msdn.microsoft.com/en-us/library/72wdk8cc.aspx

 

Diganta Kumar is an experienced Technical Program Manager with a passion for technology. He has architected and developed software for over a decade for a broad range of industries. Diganta is a founder of two online IT businesses. He likes to help, mentor, and manage software development teams to improve and produce great software. He currently works as a Principal Program Manager for Microsoft. Before joining Microsoft, he was with AWS for five years, where he managed large cross-functional programs on a global scale.

Posted in ASP.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: