码迷,mamicode.com
首页 > Windows程序 > 详细

C#-Mvc-退出登录

时间:2016-04-30 11:28:58      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:

调用MyWebApp类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Droplets.Models;
using System.Web;

namespace Droplets.WebCode
{
public static class MyWebApp
{
private const string SessionUser = "CurrentUser";
public const string LoginUrl = "/Management/Login";
public const string LogoutUrl = "/Management/Logout";

public static Admin currentUser
{
get
{
if (HttpContext.Current == null) return null;
return HttpContext.Current.Session[SessionUser] as Admin;
}
set
{
HttpContext.Current.Session[SessionUser] = value;
}
}
public static Admin checkLogin()
{
var user = currentUser;
if (user == null)
{
HttpContext.Current.Response.Redirect(LoginUrl);
}
return user;
}
public static void logout()
{
HttpContext.Current.Session.Remove(SessionUser);
}
}
}

Logout.View部分:

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Logout</title>
</head>
<body>
<div>
<h2>你已经退出登录!</h2>
<a href="/Management/Login">重新登录</a>
</div>
</body>
</html>

ManagementControllewr部分:

public class ManagementController : AppController
{
//
// GET: /Management/
Droplets.Models.DropletsEntities db;

public ManagementController()
{
db = new DropletsEntities();
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}

public ActionResult Logout()
{
MyWebApp.logout();
return View();
}

}

C#-Mvc-退出登录

标签:

原文地址:http://www.cnblogs.com/DotaSteam/p/5448292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!