Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.Net login and remember users

Posted on 2012-04-07
4
Medium Priority
?
457 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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