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

}}}

其一:

   

其二:

将文章的上传人员设置为当前用户:

再添加信息的过程中自动设置为当前用户

 

posted on 2016-04-30 10:36  ╰★╮ミ曙光ゞ  阅读(196)  评论(0编辑  收藏  举报