您的位置:首页 > 理论基础 > 计算机网络

Http 协议 请求 响应

2012-03-08 14:19 393 查看
今天 在做.net mvc 项目中 关于权限限定模块 通过重载Controller 的OnActionExecuting方法 进行 action调用前的验证

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);

#region 用户权限验证
String str =Request.Url.AbsoluteUri;
string[] strs = str.Split('/');

if (strs.Count() >= 4)
{
string skey = strs[3];

if (skey != "Login")
{
#region 用户登陆验证
if (Session["UserID"] == null || Session["current_user"] == null)
{
Session["alertInformation"] = "页面已经过期,请重新登陆!";
//filterContext.HttpContext.
Response.Redirect("/Login/Index");
//Response.Redirect("/LossCancel/Index");
Response.End();
return;
}
#endregion
if (skey != "Welcome")
{
Hashtable table = GetHashtable();
foreach (DictionaryEntry de in table)
{
if (skey.Equals(de.Key))
{
bool permission = false;

try
{
permission = new IsPermission().IsTrue(de.Value.ToString(), (string)Session["UserID"]);
}
catch (Exception ex)
{
logger.Error(ex);
Session["alertInformation"] = "页面已经过期,请重新登陆!";
Response.Redirect("/Login/Index");
Response.End(); //此处语句执行后 服务器就给浏览器响应 但本线程继续往下执行

//服务器接到响应302 立刻启动一个线程访问服务器(url:/Login/Index)

}
if (!permission)
{
Session["alertInfop"] = "对不起,您没有此权限!";
Response.Redirect("/Login/Welcome");
Response.End();
}
}
}
}

}
}

#endregion

对于 Http协议:每一次请求 对应一次响应 服务器每得到一次请求 就建立一个线程对其进行处理 并响应
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: