Results 1 to 7 of 7

Thread: Retrieving User Id

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Retrieving User Id

    We are moving some applications from Server 2003 to Server 2008R2 (IIS 7.0)

    Have following code that does not seem to work on 2008:

    Code:
    If InStr(1, UCase(Request.ServerVariables("LOGON_USER")), "\") > 0 Then
      Dim Splits() As String = UCase(Request.ServerVariables("LOGON_USER")).Split("\"c)
      Session("@User_Id") = Splits(1) 'this will be second part 
    End If
    We are using the 'log on' to check wether a user is authorized to an application. This working fine in 2003.

    Is there an equivalent in 2008 or even better, something that works both in 2003 and 2008?

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Retrieving User Id

    Never used that but a big one is the movement from IIS6 to IIS7 . Make sure you implement the authorization correctly.
    Also have a look:
    http://support.microsoft.com/kb/306359
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: Retrieving User Id

    Have now tried below options and sill cannot get the log on user id in IIS 7.0

    Code:
    If InStr(1, UCase(Request.ServerVariables("LOGON_USER")), "\") > 0 Then
                    Dim Splits() As String = UCase(Request.ServerVariables("LOGON_USER")).Split("\"c)
                    Session("@User_Id") = Splits(1) 'this will be second part 
    End If
    Code:
     
    If InStr(1, UCase(System.Security.Principal.WindowsIdentity.GetCurrent().Name), "\") > 0 Then
                    Dim Splits() As String = UCase(System.Security.Principal.WindowsIdentity.GetCurrent().Name).Split("\"c)
                    Session("@User_Id") = Splits(1) 'this will be second part 
    End If
    Code:
     If InStr(1, UCase(HttpContext.Current.User.Identity.Name), "\") > 0 Then
                    Dim Splits() As String = UCase(HttpContext.Current.User.Identity.Name).Split("\"c)
                    Session("@User_Id") = Splits(1)
    End If
    Code:
       
    If InStr(1, UCase(Request.ServerVariables("REMOTE_USER")), "\") > 0 Then
                    Dim Splits() As String = UCase(Request.ServerVariables("LOGON_USER")).Split("\"c)
                    Session("@User_Id") = Splits(1) 'this will be second part 
    End If
    Code:
    If InStr(1, UCase(Request.ServerVariables("AUTH_USER")), "\") > 0 Then
                    Dim Splits() As String = UCase(Request.ServerVariables("LOGON_USER")).Split("\"c)
                    Session("@User_Id") = Splits(1) 'this will be second part 
    End If
    Code:
    If InStr(1, UCase(Request.ServerVariables("UNMAPPED_REMOTE_USER")), "\") > 0 Then
                    Dim Splits() As String = UCase(Request.ServerVariables("LOGON_USER")).Split("\"c)
                    Session("@User_Id") = Splits(1) 'this will be second part 
    End If

    My pool is set to

    Anonymous Authenticatio = Disabled
    Windows Authentication - Enabled
    Managed Pipeline Mode = Integrated

    .Net Authorization Rules = Allow All Usres

    Application:

    <authentication mode="Windows"/>

    Any suggestions where to look or what to try??? Thank you all.
    Last edited by snufse; Nov 14th, 2013 at 10:24 AM.

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Retrieving User Id

    Have never tried something like that so...
    What is the error that you get?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Retrieving User Id

    Hello,

    Is the site that you are testing with added to the local intranet zone in Internet Explorer?

    Also, doing a bit of googling, it would appear that ServerVariables is deprecated, so I would avoid using that, but some of your other methods should work. I saw mention of rebooting of the server for the authentication changes to take effect. Have you tried rebooting the machine?

    Gary

  6. #6

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: Retrieving User Id

    There is no error just that the string containing the credtials is empty.

    I am trying to work with below, on local and server 2003 it works fine, but not on 2008.

    Any suggestion?

    Code:
    Dim User = System.Security.Principal.WindowsIdentity.GetCurrent.User
    Dim Splits() = User.Translate(GetType(System.Security.Principal.NTAccount)).Value.Split("\"c)
    Session("@User_Id") = Splits(1)

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Retrieving User Id

    I am assuming that you have enabled Windows Authentication. Is this happening when deployed to IIS on the machine, or when running out of Visual Studio?

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width