winform中保存用户后的信息应该放在哪儿最好呢?
因为可能多个客户用户同时登录,为了性能不考虑存入服务端的数据库中。
登录后,有名称,级别,权限,个人设置等要保存。
原来WebForm都是放在Cache中的,那Winform应该放在哪呢,谢谢。
问题点数:20、回复次数:3Top
1 楼fangwancong(聪头.珠海)回复于 2005-08-03 15:53:18 得分 0
public static Name ...Top
2 楼greystar(greystar)回复于 2005-08-03 15:59:09 得分 0
可以将一些个人信息,ID,权限等设置到安全主体中。说白了,就是设置到线程信息中去。Top
3 楼greystar(greystar)回复于 2005-08-03 16:02:31 得分 20
private void ultraButton1_Click(object sender, System.EventArgs e)
{
try
{
if (!SecurityManager.Authenticate(txtUser.Text,txtPassword.Text))
{
MessageBox.Show("验证用户失败,请检验用户名与密码是否正确!",Text,MessageBoxButtons.OK,MessageBoxIcon.Warning );
return;
}
else
{
// 设置安全主体
System.AppDomain.CurrentDomain.SetThreadPrincipal(
new CustomPrincipal(new CustomIdentity(txtUser.Text))
);
this.DialogResult=DialogResult.OK;
this.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
用的时候取出来
using System;
using System.Security.Principal;
using System.Threading;
using JadeSoft.Security.Principal;
namespace JadeSoft.Common
{
/// <summary>
/// Permisser 的摘要说明。
/// </summary>
public sealed class Permisser
{
static CustomPrincipal principal;
private Permisser()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
static Permisser()
{
principal=System.Threading.Thread.CurrentPrincipal as CustomPrincipal;
if(principal==null)
throw new JadeSoft.Security.SecurityException("当前用户未经授权的访问系统");
}
/// <summary>
/// 检查当前线程负责人是否有某项权限
/// </summary>
/// <param name="rightName"></param>
/// <returns></returns>
public static bool CheckRight(string rightName)
{
return principal.IsAuthorized(rightName);
}
/// <summary>
/// 返回当前用户的用户名
/// </summary>
public static string CurrentUserName
{
get
{
return ((CustomIdentity)principal.Identity).EmpName;
}
}
/// <summary>
/// 返回当前用户的GUID
/// </summary>
public static Guid CurrentUserGuid
{
get
{
return ((CustomIdentity)principal.Identity).EmpGuid;
}
}
}
}Top




