简体   繁体   中英

log off and be redirect to home page in different area

Im trying to log out of a page and have it redirect back to the home page but it cant seem to itself out of the area.

<div class="container">
<div class="pull-right">
<div class="span12">
@using (Html.BeginForm("LogOff", "Account", new { area = ""}, FormMethod.Post, new { id = "logoutForm" }))
{
   @Html.AntiForgeryToken()
   <text>
  Hello, @Html.ActionLink(User.Identity.Name, "Manage", "Account", htmlAttributes: new { @class = "username", title = "Manage" })!    |     <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
  </text>
}
</div>
</div>
</div>

This above is the _LoginPartial.cshtml.
when you log in it sends you to a member area then when you hit log off the url changes to /member/account/logoff which looks like its trying to find the account controller in the member area to invoke actionresult of logoff but the account controller is in the root of the project where it was originally created in.

That syntax looks correct. Is AccountController in a separate area than the default main area? You can also give this a try - https://t4mvc.codeplex.com/documentation . You can look at how Html.BeginForm is specified in that. The strong typing helps you avoid typos and mistakes.

I figured it out, I was using the wrong constructor. I needed to put null as a parameter at the end to use the correct constructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM