1
votes

Now, when somebody logout- i pass to logout action url, from which page he did it. But the problem, that i cant fire controller's action of url, where he pressed exit.

For example, user was on page

site.com/cabinet/home/index

and here pressed url like:

site.com/Account/LogOut/?returnURL=/cabinet/home/index

public ActionResult LogOut(string returnURL)
{
    // Need to RedirectToAction(...)
    return Redirect(returnURL);
}

So, if i redirect him to returnURL- nothing gonna happen in my controller (even not in controller,- in View, which gonna be redrawen for unathorized user (not the same interface for auth and not auth user)).

So, should i extract controller, action, area (?), params and only after this make RedirectToAction? Or any other ways to make controller be fired, when u know only url?

Thx.

2
you should to return to the URL only if loggin was done, isn't it? - Hadas
hm, dont take attantion on anything else that identify from url controller, action, area and parameters. Task: get url => get values for RedirectToAction or any other ways to fire action in controller - user1612334
Why do you need to extract the Controller and Action? You should be able to redirect to a string like "/cabinet/home/index". That's exactly what happens in the Login Action of the default AccountController in an ASP.NET MVC Internet Application. - Kristof Claes
But it doesn't fire action in controller, so i can't identify if user is authorized and redraw for him view. - user1612334
When you do return Redirect("/cabinet/home/index"); it doesn't trigger the Index action of the Home controller in the Cabinet area? What does the browser show you? Maybe it's a caching problem? - Kristof Claes

2 Answers

0
votes

in your View:

@using (Html.BeginForm("LogOut", "Account", 
    new { returnUrl = HttpContext.Current.Request.Url.LocalPath },
    FormMethod.Post))
{
<input type="submit" name="logout" value="Выход" />
}

in Action:

    public ActionResult LogOut(string returnUrl)
    {
        FormsAuthentication.SignOut();
        if (Url.IsLocalUrl(returnUrl))
        {
          //  return RedirectToAction("LogIn", "Account", new { returnUrl = returnUrl });
            return Redirect(returnUrl);
        }
        else
        {

            return Redirect(FormsAuthentication.LoginUrl);
        }
    }
-2
votes
    return RedirectToAction(ActionName, ControllerName)