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

    }

  • 相关阅读:
    课后作业之评价
    课堂作业之寻找水王
    构建之法阅读笔记04
    课下作业
    构建之法阅读笔记03
    学习进度条九
    学习进度条八
    冲刺第五天
    构建之法阅读笔记02
    冲刺第四天
  • 原文地址:https://www.cnblogs.com/DotaSteam/p/5448292.html
Copyright © 2011-2022 走看看