locked
Request.ServerVariables["LOGON_USER"] Returning Empty RRS feed

  • Question

  • User-865453959 posted

    Hey there, 

    I am trying to use the Request.ServerVariables["LOGON_USER"] method in C#, and the problem is: I'm using this method in one page, let's call it the page A, and in the page A this method is working just fine, but in another page, the page B, that is on the same server of the page A, this method isn't working, it returns empty. I have already added the authentication tag in web.config and it steel not working. Does anyone know what I'm doing wrong or what i'm missing?

    Thanks.

    Tuesday, June 9, 2015 4:16 PM

Answers

  • User1724605321 posted

    Hi Claudio,

    Thanks for your post.

    According to your description, I suggest that you could use User.Identity.Name or by using WindowsIdentity.GetCurrent().Name as follows :

    string login = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

    Request.ServerVariables("LOGON_USER") has been depreciated for C#.

    For more information , please refer to links below:

    http://forums.asp.net/t/1917277.aspx .

    https://support.microsoft.com/en-us/kb/306359 .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2015 9:05 PM

All replies

  • User724169276 posted

    Hello Claudio,

    The LOGON_USER variable will not be populated if you use the Allow Anonymous security to access the page,so make sure you disable this. In order for the LOGON_USER variable to be populated, the user must be authenticated using either Basic or NT Challenge/Response security.

    Wednesday, June 10, 2015 4:14 AM
  • User-865453959 posted

    I understand, but for example: there are two applications in the same server, that are using the same IIS. I need to configure this in the web.config of the application or in the configuration of the IIS?

    I've tried to put this code into the web.config:

    <authentication mode="Forms" />
    
    
    <!-- To deny access to the Anonymous user in the Web.config file, use the following syntax: --!>
    
    <authorization>
    <deny users = "?" /> <!-- This denies access to the Anonymous/unregistered user -->
    <allow users ="*" /> <!-- This allows access to all registered users -->
    </authorization>



    Well, it didn't worked. It's a kind of credential error or something...

    So, how could I do it?

    Thanks.

    Wednesday, June 10, 2015 3:13 PM
  • User724169276 posted

    there are two applications in the same server, that are using the same IIS.

    Both applications share same application pool or different ? If Logon_User is giving u empty then try putting both the applications under same app pool and use context.User.Identity.Name instead of Logon_User.

    Wednesday, June 10, 2015 11:30 PM
  • User1724605321 posted

    Hi Claudio,

    Thanks for your post.

    According to your description, I suggest that you could use User.Identity.Name or by using WindowsIdentity.GetCurrent().Name as follows :

    string login = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

    Request.ServerVariables("LOGON_USER") has been depreciated for C#.

    For more information , please refer to links below:

    http://forums.asp.net/t/1917277.aspx .

    https://support.microsoft.com/en-us/kb/306359 .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2015 9:05 PM
  • User-865453959 posted

    Ok, I got it. 

    Thanks, dude

    Monday, June 15, 2015 2:54 PM