シングル・サインオン・インスタンス
14200 ワード
@ Page Language
=
"
C#
"
%>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
script
runat
="server"
>
protected
void
Login_Click(object sender, EventArgs e)
{
//
Key, , 。
//
, ; 。
//
,
//
Key
string sKey
=
UserName.Text;
//
Cache Key
string sUser
=
Convert.ToString(Cache[sKey]);
//
if
(sUser
==
null
||
sUser
==
String.Empty)
{
//
Cache Key , ,
//
TimeSpan , 。
TimeSpan SessionTimeOut
=
new
TimeSpan(
0
,
0
, System.Web.HttpContext.Current.Session.Timeout,
0
,
0
);
HttpContext.Current.Cache.Insert(sKey, sKey,
null
, DateTime.MaxValue, SessionTimeOut,
System.Web.Caching.CacheItemPriority.NotRemovable,
null
);
Session[
"
User
"
]
=
sKey;
//
, 。
Msg.Text
=
"
やあ!ようこそ【 の しい 】へ
"
;
Msg.Text
+=
"
, !:)
"
;
}
else
{
//
Cache , ,
Msg.Text
=
"
し ございませんが、ログインしているようですね:-(
"
;
return
;
}
}
protected
void
Page_Load(object sender, EventArgs e)
{
Time.Text
=
"
( ):
"
+
System.Web.HttpContext.Current.Session.Timeout.ToString();
}
protected
void
Button1_Click(object sender, EventArgs e)
{
if
(Session[
"
User
"
]
!=
null
)
HttpContext.Current.Cache.Remove(Session[
"
User
"
].ToString());
}
script
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
title
>
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
align
="center"
>
<
h3
>
h3
>
<
p
>
:
<
asp:TextBox
ID
="UserName"
runat
="server"
>
asp:TextBox
>
p
>
<
p
>
:
<
asp:TextBox
ID
="PassWord"
runat
="server"
TextMode
="Password"
>
asp:TextBox
>
p
>
<
p
>
<
asp:Button
ID
="Login"
runat
="server"
Text
=" "
OnClick
="Login_Click"
>
asp:Button
>
<
asp:Button
ID
="Button1"
runat
="server"
Text
=" "
onclick
="Button1_Click"
/>
p
>
<
p
>
<
asp:Label
ID
="Msg"
runat
="server"
>
asp:Label
>
p
>
div
>
<
asp:Literal
ID
="Time"
runat
="server"
>
asp:Literal
>
form
>
body
>
html
>