会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
robot.h--为之漫笔
上海优化公司
上海装修公司
博客园
首页
订阅
管理
SETCookie
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Web.UI;
using
System.Web.Security;
using
System.Web;
namespace
Gtide.ShoppingMall.Common
{
public
class
Ticket
{
public
Ticket()
{ }
public
Ticket(Page page)
{
FormsIdentity id
=
(FormsIdentity)(page.User.Identity);
FormsAuthenticationTicket ticket
=
id.Ticket;
cookiePath
=
ticket.CookiePath;
expiration
=
ticket.Expiration;
expired
=
ticket.Expired;
isPersistent
=
ticket.IsPersistent;
issueDate
=
ticket.IssueDate;
name
=
ticket.Name;
userData
=
ticket.UserData;
version
=
ticket.Version;
}
成员
#region
成员
private
string
userData;
public
string
UserData
{
get
{
return
userData; }
set
{ userData
=
value; }
}
private
string
cookiePath;
public
string
CookiePath
{
get
{
return
cookiePath; }
set
{ cookiePath
=
value; }
}
private
DateTime expiration;
public
DateTime Expiration
{
get
{
return
expiration; }
set
{ expiration
=
value; }
}
private
bool
expired;
public
bool
Expired
{
get
{
return
expired; }
set
{ expired
=
value; }
}
private
bool
isPersistent;
public
bool
IsPersistent
{
get
{
return
isPersistent; }
set
{ isPersistent
=
value; }
}
private
DateTime issueDate;
public
DateTime IssueDate
{
get
{
return
issueDate; }
set
{ issueDate
=
value; }
}
private
string
name;
public
string
Name
{
get
{
return
name; }
set
{ name
=
value; }
}
private
int
version;
public
int
Version
{
get
{
return
version; }
set
{ version
=
value; }
}
#endregion
属性
#region
属性
private
int
userID;
public
int
UserID
{
get
{
if
(
!
string
.IsNullOrEmpty(userData))
{
userID
=
Convert.ToInt32(userData.Split(
new
char
[]
{
'
|
'
}
, StringSplitOptions.RemoveEmptyEntries)[
1
]);
}
return
userID;
}
}
#endregion
/**/
///
<summary>
///
设置验证票据
///
</summary>
///
<param name="userName">
用户名
</param>
///
<param name="userData">
用户数据,如roles等,userdata中存储roles|userid
</param>
public
void
SetTicket(
string
userName,
string
userData)
{
建立role-based认证票据
#region
建立role-based认证票据
FormsAuthenticationTicket authTicket
=
new
FormsAuthenticationTicket(
1
,
//
version
userName,
//
name
DateTime.Now,
DateTime.Now.AddMinutes(
20
),
//
expiration
false
,
//
isPersistent
userData
//
userData
);
//
修改票据cookie,加密
string
encryptedTicket
=
FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie
=
new
HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
//
保存cookie
HttpContext.Current.Response.Cookies.Add(authCookie);
#endregion
}
}
}
posted @
2007-05-23 19:51
roboth
阅读(
285
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告