.NET1.1无Cookie SessionID重写
if (String.CompareOrdinal(mac1, mac2) != 0)
{
RedirectUrl(current);
}
}
else
{
RedirectUrl(current);
}
} private void RedirectUrl(HttpContext current)
{
//重定向页面以重新生成新的SessionID
current.Response.Redirect(current.Request.Url.ToString(),true);
}
private string GetValidationKey ()
{
string key = DateTime.Now.ToShortDateString();
return key;
}
private string GetSession (HttpContext current, string name)
{
object id = FindSession(current.Session,name);
if (id == null)
{
// 将用户客户端信息加密存储在Session中以便比对
id= current.Session.SessionID+GetSessionIDMac (current.Session.SessionID, current.Request.UserHostAddress,
current.Request.UserAgent, _ValidationKey);
current.Session[name] = id;
}
return id.ToString();
}
private object FindSession (HttpSessionState session, string name)
{
return session[name];
} private string GetSessionIDMac (string id, string ip, string agent, string key)
{
StringBuilder builder = new StringBuilder (id, 512);
builder.Append (ip);
builder.Append (agent);
using (HMACSHA1 hmac = new HMACSHA1 (Encoding.UTF8.GetBytes (key)))
{
return Convert.ToBase64String (hmac.ComputeHash (
Encoding.UTF8.GetBytes (builder.ToString ())));
}
}
public void Dispose () {}
}相关配置如下:
<configuration>
<system.web>
<httpModules>
<add name="SecureSession" type="SecureSessionModule,SecureSessionModule" />
</httpModules>
</system.web>
</configuration>
大家看了代码后就会知道,它实现的原理主要是因为不可能有相同IP电脑客户端同时访问一台服务器,当出现SessionID相同但他们客户端信息不同时就自动将后一个访问的客户端重定向以新建一个会话。
遗憾的是在WAP上应用时就有问题了,由于客户端信息没IP唯一标识(移动不给手机号信息了),所以如果相同型号的手机访问时就无法区分,不知哪位高人有没更好的解决办法,还望不吝赐教
你有email邮箱吗?经常收到垃圾邮件而烦吗?立即使用邮箱LOGO在线制作酷Email logo图片










文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面