All,
I have been trying for a few days to Convert the code below to asp.net c#.
It's a pretty simple page.
- Get the current logged on user and store it in a variable called strFullUserName for example domain\johnsonM
- I then Query the user name against a stored procedure called usp_GetDisplayName example Mike Johnson.
- It will then store the users full name (Mike Johnson) in strFullUserName
I have never used C# before and I have the rest of the site already completed and now I need to display the Full Users name on the website without querying Active directory. I have done this many times in ASP using the code below without any issues just not sure how to do this is ASP.net and C#.
Thanks!
<<blockquote class="quote"><div class="op">Quote:</div>html>
<body>
<%
Dim strFullUserName
strFullUserName = Request.ServerVariables("AUTH_USER")
Set rs = CreateObject("ADODB.Recordset")
rs.Open "EXECUTE usp_GetDisplayName '" & Request.ServerVariables("AUTH_USER") & "'", "Provider=SQLOLEDB.1;Password=PASSWORD!;Persist Security Info=True;User ID=USERNAME;Initial Catalog=UserCatalog;Data Source=SERVERNAME", 3, 3
If rs.bof and rs.eof Then
Else
strFullUserName = rs.Fields("displayName").Value
End If
Set rs = Nothing
Response.Write(strFullUserName)
%>
</body>
</html</blockquote>>
What I have tried:
- I have attempted to make a connection to the sql server using the code below
}
SqlConnection sqlConnection1 = new SqlConnection("Data Source = SERVERNAME; user id = USER NAME; password = PASSWORD!; Initial Catalog = USERCATALOG;");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;