user.identity.name doesn't work on server

Last post 04-17-2007 5:29 PM by BhaveshPatel. 20 replies.

Sort Posts:

  • user.identity.name doesn't work on server

    08-31-2004, 9:24 AM
    • Loading...
    • lovedog
    • Joined on 11-05-2003, 9:34 AM
    • Posts 12
    Hi Folks,
    I'm trying to use Windows authentication on my pages. First, I made a user control which, if user.identity.name is nothing, display a login button, otherwise display the user name. Then I embedded this control on my homepage. The homepage worked perfectly when I run it locally, my Windows login name was displayed. However, when I tried it on the server, my Windows login name couldn't be found anymore, in other words, user.identity.name returns nothing.
    Have anybody had the same problem? How did you resolve it? Thanks a lot in advance.
  • Re: user.identity.name doesn't work on server

    08-31-2004, 10:28 AM
    • Loading...
    • lovedog
    • Joined on 11-05-2003, 9:34 AM
    • Posts 12
    For a better understanding of the situation, here is what I've done and found.

    Web.config
    <authentication mode="Windows" />
    <authorization>
    <allow users="*" />
    <deny users="?" />
    </authorization>

    On the server Internet Service Manager, if I check off "Anonymous Acess" under Directory Security section, the page will always pop up a windows login box, which asks username, password and domainname. Once they are correctly typed in, user.identity.name will return the user name. But what I want is the user name without the popup login. Anybody can help?
  • Re: user.identity.name doesn't work on server

    08-31-2004, 10:53 AM
    • Loading...
    • ranganh
    • Joined on 02-11-2004, 11:35 PM
    • India
    • Posts 2,423

    Hi,

    If you check the User.Identity.Name in an usercontrol, you have to change the code to

    Page.User.Identity.Name, since you are checking the identity of the user who is accessing the page and not the usercontrol, basically usercontrols are just parts of the page.

    So, change it to Page.User.Identity.Name and you should get the logged in user name.

    I wonder how it worked in your local app.

    Write back if it doesnt help.

    thanks.
    regards,
    Harish

    http://geekswithblogs.net/ranganh
  • Re: user.identity.name doesn't work on server

    01-10-2007, 11:54 AM

    Hi Harish and Lovedog...

       Plz guys need your help..

        Hey guys I am facing the same problem as Lovedog does.. like Page.User.Identity.Name doesnt work if i check on annonymous access, but if i check off annonymous access, it works fine except keep throwing the pop-up window for username and password.... I even tried using Page.User.Identity.Name rather than User.Identity.Name.. but still it is giving me same problem.

        Just for information, I am using this windows identity in Master page rather than in usercontrol.. but its same thing.

    Plz guys help me out in this... i m stuck badly here...

    work smarter, Not Harder.

    Bhavesh Patel
  • Re: user.identity.name doesn't work on server

    01-10-2007, 12:23 PM
    • Loading...
    • anught
    • Joined on 04-28-2004, 10:16 AM
    • Posts 145

    Not sure if it will help but I use:

    HttpContext.Current.User.Identity.Name.ToString

    But this is for forms authentication ...

     

    Andrew

  • Re: user.identity.name doesn't work on server

    01-10-2007, 12:58 PM
    that wouldnt work, bcoz I am working on intranet website... so I am using Windows authentication and can not use form authentication. thanks for considering this question..... but still its not answered ?????????????
    work smarter, Not Harder.

    Bhavesh Patel
  • Re: user.identity.name doesn't work on server

    01-11-2007, 3:40 AM
    • Loading...
    • ranganh
    • Joined on 02-11-2004, 11:35 PM
    • India
    • Posts 2,423

     

    Hi,

    If you are using User.Identity.Name and implementing Windows Authentication, make sure that you turn off anonymous access in your Web.Config.

    Your Web.Config should read as follows:-

    <authentication mode="Windows" />
    <authorization>
    <deny users="?" />
    </authorization>

    Write back if this still doesnt help. 

    Thanks.

     

     

     

     

    regards,
    Harish

    http://geekswithblogs.net/ranganh
  • Re: user.identity.name doesn't work on server

    01-11-2007, 10:03 AM
    • Loading...
    • Skip_Frog
    • Joined on 12-20-2006, 5:30 PM
    • Posts 171
    I had the same problem that I resolved by turning off anonymous access in IIS. Not sure if I should have done in the web.config file instead?
  • Re: user.identity.name doesn't work on server

    01-11-2007, 11:54 AM

    I tried as u mentioned.. as making changes like below to my web.config and turning off the anonymous access. still it is poping up the username and password window.

    <

    system.web>

               <

    compilation debug="true"/>

              <

    authentication mode="Windows"/>

             <

    authorization>

                 <

    deny users="?" />

             </

    authorization>

    </

    system.web>

       is there anything like this application(when I am publishing to the server) has not enough privileges to access the username from IIS? I am not master of asp.net or IIS.. I just started working on it.

       or is there any other Idea for it???

    work smarter, Not Harder.

    Bhavesh Patel
  • Re: user.identity.name doesn't work on server

    01-12-2007, 7:20 AM
    • Loading...
    • ranganh
    • Joined on 02-11-2004, 11:35 PM
    • India
    • Posts 2,423

     

    In the IIS, make sure that for this virtual directory, you have turned on "Allow Anonymous Access"  It would be in the "Directory Security" Tab of the Virtual Directory Properties.

    Basically the "Allow Anonymous Access" checkbox should be checked.

    Write back if this still doesnt help.

    Thanks.

    regards,
    Harish

    http://geekswithblogs.net/ranganh
  • Re: user.identity.name doesn't work on server

    01-12-2007, 7:37 AM
    • Loading...
    • jae.lee
    • Joined on 12-06-2006, 1:37 AM
    • Fort Lee, NJ
    • Posts 192

    when you validate, you indicated you are using user.identity.name being nothing as indicator for valid authentication.

    you can do two things.

    1. configure web.config to have: (this will allow you server's AD or integrated authentication to take care of authentication.

    		<authentication mode="Windows"/>
    		<authorization>
    			<deny users="?"/>
    		</authorization>

     2. instead of using USER.IDENTITY.NAME, use following:

    My.User.IsAuthenticated

     this is a BOOLEAN which will return if your user is authenticated or not.

    hope this helps.

    Jae.

    www.jaelee.com :: thoughts on .net development and related subjects
  • Re: user.identity.name doesn't work on server

    01-12-2007, 10:20 AM

    Hi folks... first of all thanks for replying.... thanks a lot

           To Harrish, as u mentioned "Allow Anonymous Access" checkbox should be checked",  which shouldnt be, bcoz if To Anonymous Access is checked(on), then IIS wont even bother for username or any credantials from which the web page is being requested and the output for the user.Identity.Name will be NULL string only. I have already tried it and it is returning Null string, so by either a way, "Allow Anonymous Access" should be checked off or by using web.config     <authorization> <deny users="?"/> </authorization>... I have to disable the Anonymous access.

    To Jae,

       I am basically using this code Visible='<%# Page.User.IsInRole("DOMAINNAME\\USERNAME") %> in a one button in each page and also using Page.User.Identity.Name concept in my master page. so to keep that two things on working, I have to disable the anonymous access and enable Windows authentication. I tried using all below different configuration in web.config:

    (1) Anonymous Access Box checked off(disabled)

       <

    compilation debug="true"/>

          <

    authentication mode="Windows"/>

          <

    authorization>

            

            <allow users="*" />

         </

    authorization>

    (2) Anonymous Access Box checked on(enabled) [NOTE: but still I am disabling it by below web.config]

       <

    compilation debug="true"/>

          <

    authentication mode="Windows"/>

          <

    authorization>

              <deny users="?" />  

          

    </authorization>

        <identity impersonate="true" />

    I think this would help you guys in better way to solve this issue....

    Once again thanks a lot for your previous reply and time.

    work smarter, Not Harder.

    Bhavesh Patel
  • Re: user.identity.name doesn't work on server

    01-12-2007, 2:54 PM
    • Loading...
    • jae.lee
    • Joined on 12-06-2006, 1:37 AM
    • Fort Lee, NJ
    • Posts 192

    <authentication> tags only determine how your IIS will either allow or not allow connections to the server. (it's a behavior issues)

    However, you should really look at my second comment on using my.user.isauthenticated to design your authentication criteria rather than to just check if user is missing username or not.

    It's incorrect methods also will not return constant results amongs differnt settings and servers.

    Let me know....

    Hope this helps.

    Jae.

    www.jaelee.com :: thoughts on .net development and related subjects
  • Re: user.identity.name doesn't work on server

    01-12-2007, 4:21 PM

    Hi jae, thanks for yr answer... I tried your second comment my.user.isauthenticated , but it is giving me compilation error like below:

            " The name 'my' does not exist in the current context "

    Is that any library or directory that I need to add in my project to use this "my" object or class ????

         Also guys, here is one more thing that I tried, I created very simple page with one label on it and applying text to that label from code behind file as below :

    protected

    void Page_Load(object sender, EventArgs e)

          lbl_UserName.Text = "Your are: " + Page.User.Identity.Name.ToString();  }

    with Web.cofig as following:

    <

    system.web>   

     <

    compilation debug="true"/>

        <

    authentication mode="Windows"/>

              <

    authorization>

                     <

    deny users="?" />  // To disable Anonymous User

              </

    authorization>

    </

    system.web>

     

    Then I uploaded this whole application to our server (server 2003, IIS 6)..... The output is so confusing me.

    OutPut : its kind of random, sometimes the page displays the DOMAINNAME\USERNAME with out any pop up and sometimes its just keep poping up the window for username and password,even if i entered the correct password and username, it redirects the IE to this message "you are not authorized to view this page"

    its real kind of weired for me..... cant come up with any idea on this, any further help???

    work smarter, Not Harder.

    Bhavesh Patel
  • Re: user.identity.name doesn't work on server

    01-16-2007, 2:07 AM