I have some protected pages and login form. After login I need to redirect to /home-protected/ or to page which was requested before. I was wondering how I can get return url?
I think that you should have a look on this blogpost from the Umbraco Christmas calendar from 2012 about creating a Login form with Umbraco MVC SurfaceController by Jonas Eriksson
This is what i have on my login that stores the page they were visiting before redirected to the login page.
var checkUrl = HttpContext.Current.Request.Url.AbsolutePath;
@*// add a trailing / if there isn't one (you can access http://mydomain.com/login or http://mydomain.com/login/*@
if (checkUrl[checkUrl.Length - 1] != '/')
{
checkUrl = checkUrl + "/";
}
@* if we dont have a session variable and have a request URL then store it *@
@* we have to store it because if user tries an incorrect login then Current.Request.Url will show /umbraco/RenderMvc *@
if (HttpContext.Current.Request.Url.AbsolutePath != "/umbraco/RenderMvc" &&
HttpContext.Current.Session["redirectURL"] == null)
{
if (checkUrl != "/account/login/")
{
HttpContext.Current.Session["redirectURL"] = HttpContext.Current.Request.Url.ToString();
}
}
if (User.Identity.IsAuthenticated)
{
var redirectUrl = (string) HttpContext.Current.Session["redirectURL"];
if (!string.IsNullOrEmpty(redirectUrl))
{
// clear the session variable for future logins
//
HttpContext.Current.Session["redirectURL"] = null;
HttpContext.Current.Response.Redirect(Model.Url == redirectUrl ? "/" : redirectUrl);
}
else
{
// Nothing in the session so we will go home
HttpContext.Current.Response.Redirect("/");
}
}
Member login
Hello,
I have some protected pages and login form. After login I need to redirect to /home-protected/ or to page which was requested before. I was wondering how I can get return url?
Umbraco v7
Thanks, Oleg
Hi Oleg,
I think that you should have a look on this blogpost from the Umbraco Christmas calendar from 2012 about creating a Login form with Umbraco MVC SurfaceController by Jonas Eriksson
http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller/
And here is a similar topic: http://our.umbraco.org/forum/using/ui-questions/57084-Redirect-after-login
Hope this helps,
/Dennis
Hi Dennis,
Thanks.
If I go to /only-for-members/ page I need to be redirected to this page after login.
But if I go directly to /signin/ page I need to be redirected to /home-protected/ page.
So, I can do the following
if Request.Url == /signin/ => Redirect("/home-protected/")
but
if Request.Url != /signin/ => RedirectToCurentUmbracoUrl()
I wonder if there is other way to do it.
Thank you, Oleg
hi Oleg,
This is what i have on my login that stores the page they were visiting before redirected to the login page.
Hope that helps you out.
Damian
Do work it?
Solved.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.