locked
HttpContext.Current.User.Identity.Name returning different values for IE9 and Firefox 31.4 RRS feed

  • Question

  • User1511870887 posted

    I am getting different values for HttpContext.Current.User.Identity.Name for IE9 and Firefox 31.4  for ASP.net4.5.  This is on the server with IIS7.

    So, with Firefox the domain name is being appended before the username.  Not so with IE.

    I have used this with ASP.net 3.5 and the there is no appending of the domain name in Firefox.
    What is going on? 

    This is a new site I am developing and don't have the authentication piece completely done.  I am currently using FormsAuthentication.RedirectFromLoginPage to auto log in.

    Login code...

    protected void btnDeveloperLogin_Click(object sender, EventArgs e)
            {
                FormsAuthentication.RedirectFromLoginPage("scott.metzger", false);
            }

    Code to get username

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    lblApplicationName.Text = Membership.ApplicationName;
                    lblPageLoad.Text = "Page has been loaded";
                    lblusername.Text = HttpContext.Current.User.Identity.Name;
               
                }
    
            }

    So, why does

    HttpContext.Current.User.Identity.Name return <mydomain>/scott.metzger with Firefox and just scott.metzger with IE?



    Wednesday, February 25, 2015 11:13 AM

Answers

  • User1511870887 posted

    I figured out was what causing the issue.  Symptoms were more random than what I first thought.  Sometimes IE would report username and sometimes it would report back MyDomain\username.  Firefox was more consistently coming back with MyDomain\username  but would occasionally come back with username.


    This is a new website, just setting it up.  I had uploaded the web.config file which _only_ had forms authentication enabled.

    For some reason when examining the settings via the IIS 7 GUI it showed that both Forms and Windows Authentication was enabled.  I disabled Windows Authentication and now I am consistently getting just username reported back.

    But... this begs the question... Why was Windows Authentication enabled when looking through the IIS GUI, yet it was not in the web.config ?  What is going on here?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 26, 2015 8:52 AM

All replies

  • User1644755831 posted

    Hi smetzger,

    I tried to reproduce your issue using windows authentication.

    <system.web>
        <authentication mode="Windows"></authentication>
        <!--<authentication mode="Forms"></authentication>-->
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
      </system.web>
    protected void Page_Load(object sender, EventArgs e)
        {
          if (User.Identity.IsAuthenticated)
          {
            //Response.Write("Home page for " + User.Identity.Name);
            Response.Write("Home page for " + HttpContext.Current.User.Identity.Name);
          } 
          else
          {
            Response.Write("Home page for " + HttpContext.Current.User.Identity.Name);
          }
        }

    I was using IE11 and asp.net 4.5. I was not able to reproduce the issue. 

    It should not matter what browser you are using since this is server side code. I mean what ever the browser that is client side your code will run on the server side.

    It showed MyDomain\usename when I ran the project.

    can you please provide a sample in which this issue is reproducible ?

    with Regards,

    Krunal Parekh

    Thursday, February 26, 2015 3:50 AM
  • User1511870887 posted

    I figured out was what causing the issue.  Symptoms were more random than what I first thought.  Sometimes IE would report username and sometimes it would report back MyDomain\username.  Firefox was more consistently coming back with MyDomain\username  but would occasionally come back with username.


    This is a new website, just setting it up.  I had uploaded the web.config file which _only_ had forms authentication enabled.

    For some reason when examining the settings via the IIS 7 GUI it showed that both Forms and Windows Authentication was enabled.  I disabled Windows Authentication and now I am consistently getting just username reported back.

    But... this begs the question... Why was Windows Authentication enabled when looking through the IIS GUI, yet it was not in the web.config ?  What is going on here?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 26, 2015 8:52 AM
  • User1644755831 posted

    Hi smetzger,

    But... this begs the question... Why was Windows Authentication enabled when looking through the IIS GUI, yet it was not in the web.config ?  What is going on here?

    Please create another thread for this.

    With Regards,

    Krunal Parekh

    Thursday, March 5, 2015 1:08 AM