Solved

ASP.Net login and remember users

Posted on 2012-04-07
4
449 Views
Last Modified: 2012-04-12
I have an ASP.Net site. I'm using membership ad the login control. I need the remember me option to work. Right now it does not. I set the sessionsate timeout to 1440 in the web.config file. The code in the site master page is below. Is ther something that will cause the remember me option to not work? I'm not very familiar with the login/logout process. Thanks.

    protected void Page_Load(object sender, EventArgs e)
    {
        string name = SessionHelper.GetFirstName();

        Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Page.Response.Cache.SetExpires(DateTime.Now - new TimeSpan(1, 0, 0));
        Page.Response.Cache.SetLastModified(DateTime.Now);
        Page.Response.Cache.SetAllowResponseInBrowserHistory(false);
        Page.Response.Cache.SetNoStore();
        if (Request.IsAuthenticated)
        {

        }
        else
        {
            Response.Redirect("~/Default.aspx");
        }
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Page.Response.Cache.SetExpires(DateTime.Now - new TimeSpan(1, 0, 0));
        Page.Response.Cache.SetLastModified(DateTime.Now);
        Page.Response.Cache.SetAllowResponseInBrowserHistory(false);
        Page.Response.Cache.SetNoStore();
    }

    protected void HeadLoginStatus_LoggedOut(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Roles.DeleteCookie();
        Session.Clear();
    }
0
Comment
Question by:dodgerfan
  • 2
4 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 37820630
if (Request.Cookies["myCookie"] != null)
        {
            HttpCookie cookie = Request.Cookies.Get("myCookie");
            String UserName = cookie.Values["username"];
            this.Login1.RememberMeSet = !(String.IsNullOrEmpty(UserName));
        }


Reference:
http://forums.asp.net/t/1087450.aspx/1
http://forums.asp.net/t/1784284.aspx/1
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37821008
Once they're authenticated call FormsAuthentication.SetAuthCookie(UserName, true);

Setting the second parameter to true tells it to persist across sessions
0
 

Author Comment

by:dodgerfan
ID: 37822150
Where does the code go? The code I posted is in my master page. Should it go there or in the login page load event?
0
 
LVL 7

Accepted Solution

by:
markmiddlemist earned 500 total points
ID: 37822253
It should go just after you have confirmed their username and password are valid on the login page
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now