Difference between User.Identity.IsAuthenticated and Request.IsAuthenticated?

Last post 07-16-2009 5:07 PM by MEight. 4 replies.

Sort Posts:

  • Difference between User.Identity.IsAuthenticated and Request.IsAuthenticated?

    07-13-2009, 3:37 PM
    • Member
      89 point Member
    • MEight
    • Member since 07-27-2005, 1:23 PM
    • Posts 106

    Obviously, User.Identity.IsAuthenticated checks to see if the User is authenticated while Request.IsAuthenticated checks to see if the Request is Authenticated.

    Just wondering what the difference between the two is.  Can they be used interchangeably or are there situations that arise that would make it more appropriate to use one over the other?

    Thanks

     

    Filed under:
  • Re: Difference between User.Identity.IsAuthenticated and Request.IsAuthenticated?

    07-14-2009, 6:01 AM
    Answer
    • Contributor
      2,752 point Contributor
    • shabirhakim1
    • Member since 03-31-2009, 11:33 AM
    • Bangalore
    • Posts 445


    Hi great man
    Good Question.
    The following code example uses the IsAuthenticated property to determine whether the current request has been authenticated. If it has not been authenticated, the request is redirected to another page where users can enter their credentials into the Web application. This is a common technique used in the default page for an application.

    private void Page_Load(object sender, EventArgs e)
    {
        // Check whether the current request has been authenticated. If it has not, redirect the  user to the Login.aspx page.
        if (!Request.IsAuthenticated)
        {
            Response.Redirect("Login.aspx");
        }
    }

     

    but when it comes to User.Identity.IsAuthenticated


    The User property provides programmatic access to the properties and methods of the IPrincipal interface. Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an .aspx page without using the fully qualified class reference to HttpContext. For example, you can use User.Identity.Name to get the name of the user on whose behalf the current process is running. However, if you want to use the members of IPrincipal from an ASP.NET code-behind module, you must include a reference to the System.Web namespace in the module and a fully qualified reference to both the currently active request/response context and the class in System.Web that you want to use. For example, in a code-behind page you must specify the fully qualified name


    protected void Page_Load(object sender, EventArgs e)


    {


        if (User.Identity.IsAuthenticated)
    //so here i am checking whether user is authenticated ,if yes i access his name also and display it on title,which i can't do in above case


        {
            Page.Title = "Home page for " + User.Identity.Name;
        }
        else
        {
            Page.Title = "Home page for guest user.";
        }
    }

    Regards shabir hakim

     

    Good is Never Good .if better is accepted
  • Re: Difference between User.Identity.IsAuthenticated and Request.IsAuthenticated?

    07-14-2009, 7:49 AM
    • Member
      215 point Member
    • nirman.doshi
    • Member since 07-07-2009, 8:07 AM
    • Vadodara
    • Posts 64

    what are the situations where Request.IsAuthenticated becomes false.

    can u just illustrate one or two of them ?

    Thanks

    Nirman Doshi
    Software Developer
    Vadodara, India
  • Re: Difference between User.Identity.IsAuthenticated and Request.IsAuthenticated?

    07-14-2009, 9:33 AM
    • Star
      10,561 point Star
    • getchinna_sv
    • Member since 09-10-2008, 8:29 PM
    • Hyderabad
    • Posts 1,802

    check this link.... http://forums.asp.net/t/1416811.aspx 

    Chinna_sv...
  • Re: Difference between User.Identity.IsAuthenticated and Request.IsAuthenticated?

    07-16-2009, 5:07 PM
    • Member
      89 point Member
    • MEight
    • Member since 07-27-2005, 1:23 PM
    • Posts 106

    Thanks everyone. Very helpful.

    So essentially they do the same job and either can be used interchangeably.

     

Page 1 of 1 (5 items)