zoukankan      html  css  js  c++  java
  • 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();
    }

    }

  • 相关阅读:
    Android常用开发工具的用法
    搭建Android开发环境
    开篇 Android系统的体系结构
    学习安卓笔记
    C# DllImport用法和路径问题
    jq 实现无限级地区联动 样式为bootstrap
    YII2 日志
    centos6.5 lamp 环境 使用yum安装方法
    mysql 时间戳 按周、日、月 统计方法 附 date格式
    Yii2.0中文开发向导——控制器(Controller)
  • 原文地址:https://www.cnblogs.com/DotaSteam/p/5448292.html
Copyright © 2011-2022 走看看