C#-Mvc-退出登录

调用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();
}

}

时间: 2024-08-20 22:38:25

C#-Mvc-退出登录的相关文章

“退出登录”button回调的实现

@OnClick(R.id.btn_user_logout) public void logout(View view){//"退出登录"button的回调方法 //1.将保存在sp中的数据清除 SharedPreferences sp = this.getSharedPreferences("user_info", Context.MODE_PRIVATE); sp.edit().clear().commit();//清除数据操作必须提交:提交以后,文件仍存在,只

退出登录功能改变window的rootviewcontroller输入框键盘不会收起

最近在公司负责做ipad开发,一个简单的需求,一个设置视图以modal的方式弹出,占据屏幕的中间一块区域,这时点击视图上的退出登录按钮,切换程序主window的rootviewcontroller为登录controller,这时问题来了,所有的输入框激活后弹出的键盘都不能自动收回,包括进入程序后其他二级页面弹出键盘返回一级页面也不会自动收回键盘,这个坑卡了我比较久的时间,还好终于被我解决了,但是这里面的深层原因我不太清楚,还望高手看到后解答. 大家可以看到我画的这两个示意图. 具体的解决办法是,

jquery 退出登录

<a onclick="return confirm('确认要退出登录吗?')">退出</a>

Meteor:关闭所有tab时退出登录

功能描述:在浏览器退出时(所有tab关闭时)退出登录 需求来源:支持类似传统网页登录时的remember me选项 背景:Meteor应用中,用户登录后,会在浏览器的localStorage保存resume token, 所以下次再使用该浏览器打开同一meteor应用时,会自动登录.有时,我们希望应用支持在浏览器退出时(所有tab关闭时)即退出登录,然而meteor被没有对这项功能的原生支持,需要我们自己实现. 要点:如何检测tab关闭,如何检测所有tab关闭 如何退出登录 调用Meteor.l

phpcms前台退出登录的时候提示信息&#39;退出成功0&#39;

问题背景: phpcms前台退出登录的时候,提示了一个退出成功0 让我很困惑为啥有个0呢? 问题分析: 进入 ./phpcms/modules/member/index.php 找到logout方法,代码如下: public function logout() { $setting = pc_base::load_config('system'); //snda退出 if($setting['snda_enable'] && param::get_cookie('_from')=='snd

WordPress设置退出登录后跳转到指定页面

做网站大家都很重视用户体验,今天给大家大家带来一个WordPress改善用户体验的方法,用户退出登录直接跳转到首页或者让它跳转到我指定的位置,下面是具体的操作方法: 1.找到您目前在用的主题文件,鼎峰网络阿D这里的是wp-content/themes/twentyfourteen/,其中themes是主题文件夹,鼎峰网络阿D之前的wordpress文件结构也有提到,twentyfourteen是目前启用的主题,找到functions.php文件: 2.在functions.php文件中添加以下代

python学习之路之案例0(实现登录功能,登录错误次数超过3次,自动退出登录)

一.整个案例运用到的知识点 1.python字典.字符串.列表的灵活转换和使用 2.python数据结构之字符串:字符串的格式化.字符串的去空格(strip()) 3.python数据结构之字典:字典的构建.字典和字符串的转换 4.python数据结构列表:列表的构建.列表和字符串的转换 5.if....else....判断的使用 6.for循环.while True死循环的使用 5.文件的打开.读取.关闭等功能的使用 二.整个案例的设计的中心思想 1.首先读取用户表文件里面的字符串:包括用户名

Vue(vue+node.js+mongodb)_退出登录

一.前言 二.主要内容 1.当用户登录之后才会出现“退出登录按钮” 2.登录之后  3.这里使用mint-ui, “退出登录”按钮的显示隐藏和是否有userInfo的值是一样的,如果存在userInfo就显示这个退出按钮,如果没有登录就不显示 <section class="profile_my_order border-1px"> <mt-button type="danger" style="width: 100%" @cl

如何实现在一个测试类里只登录和退出登录一次

在进行自动化测试的时候,往往只需要登录一次和测试完成的以后,退出登录一次就好,不需要每执行一个测试用例,都登录和退出.用python 的classmethod 装饰器就能实现,伪代码如下: import unittestclass XXX(unittest.TestCase) @classmethod def setUpClass(cls): """ 这里实现一系列的登录操作 """ @classmethod def tearDownClass(

easeChat模块demo退出登录功能源码案例

代码片段: <div class="flex-vertical" id="rootWarp" v-cloak> <!--  头部 --> <header id="header"> <div class="header" :class="{on:headers.num==0}" v-for="(headers,index) in header"&g