Kianoush Kianoush - 1 month ago 12
ASP.NET (C#) Question

Access to the root controller from area

i have area in my project

Admin
,
User
.

i
Admin
i create a signout buttom . i need when click in signout button go to root and
AccountController
and use
logOff
Action .

i using this but it search in area looking to
AccountController
and
logOff
Action .

<li><i class="icon-key"></i>@Html.ActionLink("خروج","LogOff","Account")</li>


how can i solve this ?

Edit

i used exit code in index view :

@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<li><i class="fa fa-sign-out" aria-hidden="true"></i><a href="javascript:document.getElementById('logoutForm').submit()">خروج</a></li>


.

}
public ActionResult LogOff()
{
AuthenticationManager.SignOut();
return RedirectToAction("Index", "Home");
}`

Answer

Use [HttpPost] before action. For Ex. this.

[HttpPost]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}

and in view part it seems Ok. but just make submit button, like this.

@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
                {
.... Your Code .....
<input type="submit" value="Submit">
}

This is true answer if you meaned same i understand from your english.