Page 1 of 1
stay on page when logging in
Posted: Tue Jul 14, 2009 4:21 pm
by joey
On trainsignal.com when a user is on a products page and logs in, they get redirected back to the home page. Is there any way that a user can remain in the page they logged in on?
Re: stay on page when logging in
Posted: Wed Jul 15, 2009 6:11 am
by mazhar
You can try following trick, first create a user control under ConLib/Custom folder
Code: Select all
<%@ Control Language="C#" ClassName="LoginUtil" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
LoginURL.Visible = Token.Instance.User.IsAnonymous;
LogoutURL.Visible = !Token.Instance.User.IsAnonymous;
}
protected void LoginURL_Click(object sender, EventArgs e)
{
if(Request.Url.AbsoluteUri.ToLower().Contains("product.aspx"))
{
Product product = ProductDataSource.Load(PageHelper.GetProductId());
if(product != null)
Response.Redirect(string.Format("Login.aspx?ReturnUrl={0}", product.NavigateUrl));
}
Response.Redirect("Login.aspx");
}
</script>
<asp:LinkButton ID="LoginURL" runat="server" CssClass="login" onclick="LoginURL_Click">Login</asp:LinkButton>
<asp:HyperLink ID="LogoutURL" runat="server" CssClass="login" NavigateUrl="~/Logout.aspx">Logout</asp:HyperLink>
Then edit your header scriptlet and locate following code
Code: Select all
#if($customer.IsAnonymous)
<a href="~/Login.aspx" class="login">Login</a>
#else
<a href="~/Logout.aspx" class="login">Logout</a>
#end
and update it [[ConLib:Custom\LoginUtil]]
Re: stay on page when logging in
Posted: Wed Jul 15, 2009 12:14 pm
by joey
Thank you for the help, I could be wrong but it seems that this solution will only work if you are on a product page, am I correct? I was hoping that I could get something working on any page on the entire site, such as the product categories or some of the custom content pages.
Re: stay on page when logging in
Posted: Thu Jul 16, 2009 1:59 am
by mazhar
For any page try by updating LoginURL_Click to
Code: Select all
protected void LoginURL_Click(object sender, EventArgs e)
{
Response.Redirect(string.Format("Login.aspx?ReturnUrl={0}", Request.Url.AbsoluteUri.ToString()));
}
Re: stay on page when logging in
Posted: Thu Jul 16, 2009 10:57 am
by joey
Works like a charm.
I kindly thank you sir
Re: stay on page when logging in
Posted: Wed Aug 25, 2010 10:28 am
by mfreeze
In onepagecheckout.ascx.cs, can I replace the returnurl in the following lines to what you specified in this post ReturnUrl={0}", Request.Url.AbsoluteUri.ToString()));? This is release 7.0.3.
Code: Select all
if (editBilling && isAnonymous)
{
LoginPanel.Visible = true;
LoginLink.NavigateUrl = "~/Login.aspx?ReturnUrl=" + Server.UrlEncode(Request.Url.AbsolutePath);
}
And what about login.aspx which returns the user to the last page only in admin. I find the following code in login.aspx.
Code: Select all
protected void Page_Init(object sender, EventArgs e)
{
string returnUrl = NavigationHelper.GetReturnUrl(string.Empty);
if (!string.IsNullOrEmpty(returnUrl))
{
if (returnUrl.ToLowerInvariant().Contains("/admin/"))
{
Response.Redirect(NavigationHelper.GetAdminUrl("Login.aspx?ReturnUrl=" + Server.UrlEncode(returnUrl)));
}
}
}
and the following in logindialog.ascx.cs.
Code: Select all
private bool _EnableAdminRememberMe = true;
public bool EnableAdminRememberMe
{
get { return _EnableAdminRememberMe; }
set { _EnableAdminRememberMe = value; }
}
If I change login.aspx will it always return the user to the page they were on no matter what it was?