首页 新闻 会员 周边

asp.net MVC3注销的问题

0
悬赏园豆:15 [已解决问题] 解决于 2013-04-03 22:57
@if (Request.IsAuthenticated) {
    <text>
        你好,@Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { @class = "username", title = "管理" })!
        
            @Html.ActionLink("注销", "LogOff", "Account")
    </text>
} 

else 
{
    <ul>
        <li>@Html.ActionLink("注册", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("登录", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
    </ul>

}

以上是_LoginPartial.cshtml

 

// POST: /Account/LogOff

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            WebSecurity.Logout();
            return RedirectToAction("Index", "Home");
        }

为什么不能实现注销?需要添加LogOff页面吗?

sidecore的主页 sidecore | 初学一级 | 园豆:2
提问于:2013-04-01 10:53
< >
分享
最佳答案
0

你是用 cookie,还是 session 记录用户的登录信息的。

 WebSecurity.Logout(); 没有清理干净吧
收获园豆:15
geass.. | 小虾三级 |园豆:1821 | 2013-04-01 20:56

是用cookie记录的

sidecore | 园豆:2 (初学一级) | 2013-04-02 09:54
其他回答(2)
0

怎么看出不能注销?

Qlin | 园豆:2403 (老鸟四级) | 2013-04-01 12:15

“/”应用程序中的服务器错误。


 

           

无法找到资源。


           
            说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。            

            请求的 URL: /Account/LogOff

支持(0) 反对(0) sidecore | 园豆:2 (初学一级) | 2013-04-01 12:17

@sidecore: 

你的 标签是a 是get提交, 把 [HttpPost] 换成 [HttpGet]

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-04-01 12:20

@Qlin: 把 [HttpPost] 换成 [HttpGet]后,现在变成了 500 Internal Server Error

支持(0) 反对(0) sidecore | 园豆:2 (初学一级) | 2013-04-01 14:13

@sidecore: 

查看请求的 地址正确的话,    那 你要调试了,看看 哪里有问题 。

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-04-01 14:15

@Qlin: 我把[ValidateAntiForgeryToken]去掉,就可以正常注销了。[ValidateAntiForgeryToken]是作什么用的?

支持(0) 反对(0) sidecore | 园豆:2 (初学一级) | 2013-04-01 15:12
0

你最好自己写一个登陆机制,系统的不是很靠谱

WebSecurity.Logout();之后,加个Session.Clear(),再试试吧,如果需要记得登陆状态的话,可能系统提示的方式是cookies实现的,你需要在监视一下,看看cookies是否被清除了,如果没有清除,你有动清一下吧!

张占岭 | 园豆:464 (菜鸟二级) | 2013-04-02 11:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册