Stefan Motz
asked on
Capture LOGON_USER in ASP.NET MVC - C#
Hi Experts,
I'm trying to convert a Classic ASP application to .NET MVC.
I'm having difficulties with identifying the logged in user. This is how I used to do it with Classic ASP:
<%=Request.ServerVariables ("LOGON_US ER")%>
With the code below I captured the logged in users's First Name, Last Name and Employee #.
Users have the option to log in with their EMP_ID or ALT_ID
In my MVC project I can display the LOGON_USER like this:
string EmployeeLogin = System.Security.Principal. WindowsIde ntity.GetC urrent().N ame;
ViewBag.Authentication = EmployeeLogin;
When they are logged in with their EMP_ID it returns the following:
ABCDDE\U123456 - The EMP_ID is a six digit number
When they are logged in with their ALT_ID this is what is returned:
ABC\124B8 - The ALT_ID can be a combination of letters and numbers after the \
How can I display the users' names in C#?
This is my stored procedure:
I would appreciate your help.
I'm trying to convert a Classic ASP application to .NET MVC.
I'm having difficulties with identifying the logged in user. This is how I used to do it with Classic ASP:
<%=Request.ServerVariables
With the code below I captured the logged in users's First Name, Last Name and Employee #.
<%
set rs = Server.CreateObject("ADODB.recordset")
Dim UserID
UserID = UCase(Request.ServerVariables("LOGON_USER"))
UserID = Replace(UCase(UserID), "\U", "\")
if InStr( UserID, "U" ) >= 0 then
UserID = Replace( UserID, "U", "" )
end if
if InStr( UserID, "." ) > 0 then
UserID = Mid( UserID, InStr( UserID, "\" ) + 1, InStr( UserID, "." ) - InStr( UserID, "\" ) - 1 )
else
UserID = Right( UserID, Len( UserID ) - InStr( UserID, "\" ) )
end if
rs.Open "exec sp_Authentication'" & UserID & "'", Conn
do until rs.EOF
ID = rs("ID")
EMP_ID = rs("EMP_ID")
ALT_ID = rs("ALT_ID")
FIRST_NAME = rs("FIRST_NAME")
LAST_NAME = rs("LAST_NAME")
rs.MoveNext
loop
rs.Close
Set rs = Nothing
%>
<%=FIRST_NAME%> <%=LAST_NAME%> <%=EMP_ID%>
Users have the option to log in with their EMP_ID or ALT_ID
In my MVC project I can display the LOGON_USER like this:
string EmployeeLogin = System.Security.Principal.
ViewBag.Authentication = EmployeeLogin;
When they are logged in with their EMP_ID it returns the following:
ABCDDE\U123456 - The EMP_ID is a six digit number
When they are logged in with their ALT_ID this is what is returned:
ABC\124B8 - The ALT_ID can be a combination of letters and numbers after the \
How can I display the users' names in C#?
This is my stored procedure:
ALTER PROCEDURE [dbo].[sp_Authentication]
@empID varchar(15)
AS
BEGIN
SELECT [ID],
[EMP_ID],
[ALT_ID],
[FIRST_NAME],
[LAST_NAME],
FROM dbo.[Authentication]
where EMP_ID=@empID OR ALT_ID=@empID;
END
I would appreciate your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much.
ASKER