+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / HttpContext.Current.User.Identity.IsAuthenticated is false after Response.Redirect

HttpContext.Current.User.Identity.IsAuthenticated is false after Response.Redirect

5 posts, 0 answered
  1. Santanu
    Santanu avatar
    2 posts
    Registered:
    04 Sep 2012
    03 Apr 2012
    Link to this post
    Hi,
    We are working on a solution where we are using custom pages that requires User to be logged in. To test this scenario, we simply created a login page (login.aspx) with ASP.Net Login Control and another page (securepage.aspx) which should show only if the user is logged in.

    Everything works fine till be do a Response.Redirect("securepage.aspx") i.e. HttpContext.Current.User.Identity.IsAuthenticated is true till we call Response.Redirect.

    However, when we check HttpContext.Current.User.Identity.IsAuthenticated on Page_Load of securepage.aspx it is returning false.

    Currently the code is very simple and is as follows:

    //** login.aspx **
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        UserManager userManager = UserManager.GetManager();
        if (userManager.ValidateUser(Login1.UserName, Login1.Password))
        {
            e.Authenticated = true;
        }
    }
     
    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
            UserManager userManager = UserManager.GetManager();
        Telerik.Sitefinity.Security.Model.User userToAuthenticate =null;
        UserLoggingReason userLoggingReason = SecurityManager.AuthenticateUser(userManager.Provider.Name, Login1.UserName, Login1.Password, false, out userToAuthenticate);
        //bool isLoggedIn = HttpContext.Current.User.Identity.IsAuthenticated; <---- returns true
        HttpContext.Current.Response.Redirect("securepage.aspx");
    }

     


    //**securepage.aspx **
    protected void Page_Load(object sender, EventArgs e)
     {
        bool isLoggedIn = HttpContext.Current.User.Identity.IsAuthenticated;  //<--- returns false
     }

    As I read somewhere in the forum that SecurityManager.AuthenticateUser method will automatically set the required cookies etc, which means the above should work, but looks like we are doing something wrong (or something that we are not doing) due to which it is not working.

    Please Help!!

    Santanu Biswas

  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Sep 2016
    05 Apr 2012
    Link to this post
    Hello Santanu,

    Can you give us more details on your scenario? Are you using claims based authentication or forms based?

    Greetings,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Santanu
    Santanu avatar
    2 posts
    Registered:
    04 Sep 2012
    06 Apr 2012
    Link to this post
    Hi Jen,
    By the time your reply came in, we have been able to solve the problem. It was indeed a problem of Authentication type. We could solve it by selecting 'Form Based Authentication' in Sitefinity. By default 'Claim Based Authentication' was selected.
    Thanks for your reply anyways.
    Santanu
  4. mstoffel
    mstoffel avatar
    27 posts
    Registered:
    13 Jul 2005
    11 Apr 2012
    Link to this post
    Hello Jen,

    Can you please explain with a claims based authentication scenario?

    Thanks in advance
  5. David
    David avatar
    38 posts
    Registered:
    05 Apr 2012
    07 Sep 2012
    Link to this post
    Hi Jen

    Can I also please put in a call for an explanation/demo code for a claims based authentication scenario as we are having a very similar problem.

    Regards,
    David Bigg
5 posts, 0 answered