stay on page when logging in

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
joey
Ensign (ENS)
Ensign (ENS)
Posts: 17
Joined: Tue Jul 14, 2009 4:18 pm

stay on page when logging in

Post by joey » Tue Jul 14, 2009 4:21 pm

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?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: stay on page when logging in

Post by mazhar » Wed Jul 15, 2009 6:11 am

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]]

joey
Ensign (ENS)
Ensign (ENS)
Posts: 17
Joined: Tue Jul 14, 2009 4:18 pm

Re: stay on page when logging in

Post by joey » Wed Jul 15, 2009 12:14 pm

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.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: stay on page when logging in

Post by mazhar » Thu Jul 16, 2009 1:59 am

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()));
    }

joey
Ensign (ENS)
Ensign (ENS)
Posts: 17
Joined: Tue Jul 14, 2009 4:18 pm

Re: stay on page when logging in

Post by joey » Thu Jul 16, 2009 10:57 am

Works like a charm.

I kindly thank you sir

User avatar
mfreeze
Commodore (COMO)
Commodore (COMO)
Posts: 421
Joined: Mon Jan 24, 2005 2:07 pm
Location: Washington, NJ
Contact:

Re: stay on page when logging in

Post by mfreeze » Wed Aug 25, 2010 10:28 am

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?
Mary E Freeze

Freeze Frame Graphics
Web Hosting and Design, ASP and CFMX Development

http://www.ffgraphics.com

Post Reply