Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
guys i'm creating a project. i dont know how can i show a login page or to login message if user click the buttons of buy product or add to cart product withput login ???
Posted
Comments
F-ES Sitecore 11-May-15 5:32am    
Google "asp.net identity" or "asp.net membership" (Identity is more up-to-date than Membership). They are use authentication frameworks that have everything you need to manage users and allow them to login.

1 solution

Hi
while the user is clicking button buy product or add to cart button u should check whether the current user session expired or not.

for that first store user id in a session variable then check whether session["userid"]==null .if it is null redirect to login page
 
Share this answer
 
Comments
UnStable Messi 11-May-15 13:59pm    
bro i mean.. if not logged in.. like if a person just visits website then he click on add to cart or buy now button.. then message or redirect will be happen.. same like on this website. if we submit a question without sign-in... this message shows "Please log in (or quickly sign up) to post."
priyadarshini tv 12-May-15 1:31am    
Hi
That is wat i told :) .You can handle this thing globally

try this code in your global.asax session_start event
if (HttpContext.Current.Request.IsAuthenticated)
{
FormsAuthentication.SignOut();
Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" + Server.UrlEncode(Request.Url.ToString()));

}
then in your login pages's page load event try this code

if (!IsPostBack)
{

if (Request.QueryString["ReturnUrl"] != null && Session["userId"] == null)
{

lblUserLoginError.Text = "Session Expired ! Please Login again";
string script = "function f(){ HideErrorLogin(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);

}
else if (HttpContext.Current.Request.IsAuthenticated && Session["userId"] != null)
{
Response.Redirect("~/AuthenticatedUser/123.aspx", false);
}
}

Note HideErrorLogin() is a javascript function to show and hide the session expiry message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900