简体   繁体   English

注销并重定向到其他区域的主页

[英]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. 上面是_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. 当您登录时,它会将您发送到成员区域,然后当您单击注销时,URL更改为/member/account/logoff ,这似乎是它试图在成员区域中找到帐户控制器以调用注销的动作结果,但是该帐户控制器位于最初创建该项目的项目的根目录中。

That syntax looks correct. 该语法看起来正确。 Is AccountController in a separate area than the default main area? AccountController是否位于与默认主区域不同的区域中? You can also give this a try - https://t4mvc.codeplex.com/documentation . 您也可以尝试一下-https: //t4mvc.codeplex.com/documentation You can look at how Html.BeginForm is specified in that. 您可以查看其中如何指定Html.BeginForm。 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 我需要在最后放置null作为参数以使用正确的构造函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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