Solved

ASP.Net login and remember users

Posted on 2012-04-07
4
448 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

21 Experts available now in Live!

Get 1:1 Help Now