需调用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);
}}}
其一:
其二:
将文章的上传人员设置为当前用户:
再添加信息的过程中自动设置为当前用户