Hi,
I am pretty new to MVC. Started with simple login and logout links on a page.
When I click on Log out link, the form is not logging out actually.
Here's my code,
[HttpPost]
public ActionResult LogOut()
{
if (Request.IsAuthenticated)
{
FormsAuthentication.SignOut();
}
return View();
}
I even tried some other stuff like "Response.Cookies.Clear();" but no use.
If a log in is successful, I want to display some links in the menu to navigate to other pages.
So I took a _loginpartial view and kept in a Layout page.
The _loginpartial view is
@if (Request.IsAuthenticated) {
<text>
<div class="float-right">
Hello, @Html.Encode(User.Identity.Name)
@using (Html.BeginForm("LogOut", "User", FormMethod.Post, new { id = "logoutForm" })) {
<a href="java<!-- no -->script:document.getElementById('logoutForm').submit()">Log out</a>
}
<br /><br />
@Html.ActionLink("Publishers", "Index", "Publisher")
@Html.ActionLink("Customers", "Index", "Customer")
@Html.ActionLink("Authors", "Index", "Author")
</div>
</text>
} else {
@Html.ActionLink("Register", "Register", "User", routeValues: null, htmlAttributes: new { id = "registerLink" })
@Html.ActionLink("Log in", "Login", "User", routeValues: null, htmlAttributes: new { id = "loginLink" })
}
I even tried to give a layout as null in Log out view.
I don't know whether we could check the Request.IsAuthenticated property in viewstart page, but
I also tried to give a layout as null in viewstart if user is not authenticated.
Help me on this..
Thanks in advance.