?
Solved

ASP.Net login and remember users

Posted on 2012-04-07
4
Medium Priority
?
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Rahul Agarwal
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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