I am having issues about redirection to a page after using the Custom Login/Logout.
The scenario is, I need to redirect the user to the Custom Login page, if accessing the Restricted Page (Test Restrict). I can now redirect him to Login Page and can even log in using his Sitecore credentials. After successful login, user is being redirected to the Test Restrict and also seeing the Logout Button.
I have configured the Logout Button that should redirect user to the /sitecore/content/Site/Home
when clicked. However, if the Home Page is also restricted to anonymous users, I keep getting a message
Layout request not found
Below is a snippet of my code.
[HttpPost]
[ValidRenderingToken]
public ActionResult Logout(Login loginModel)
{
var model = GetDataSourceItem<Login>();
AuthenticationManager.Logout();
Session.Abandon();
FormsAuthentication.SignOut();
model.LoginUsername = "";
model.LoginPassword = "";
var linkUrl = model.TargetPageUrl;
if (string.IsNullOrEmpty(linkUrl))
{
SetReturnUrl();
}
else
{
ReturnUrl = linkUrl;
}
return Redirect(string.IsNullOrEmpty(ReturnUrl) ? "/" : ReturnUrl);
}
private void SetReturnUrl()
{
if (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
ReturnUrl = Request.QueryString["returnUrl"];
}
I am new to this and would like to ask for advice/help. Thanks