Solved

ASP.Net login and remember users

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jquery datatables, asp.net MVC 9 39
Error handling in asp.net site 5 25
Problem!!! 8 33
VB.NET 2008 - SQL Timeout 9 23
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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