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协议:每一次请求 对应一次响应 服务器每得到一次请求 就建立一个线程对其进行处理 并响应
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协议:每一次请求 对应一次响应 服务器每得到一次请求 就建立一个线程对其进行处理 并响应
相关文章推荐
- HTTP协议--请求与响应
- HTTP协议的请求与响应
- 接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。
- HTTP协议中request报文请求方法和状态响应码
- 有关http协议中的请求头和响应头 各个单词的含义
- Http协议请求响应模型(一次请求的生命周期或简单的软件分层)
- http协议2:请求、响应、缓存
- HTTP协议2:请求、响应、缓存 2017-03-16 11:20 197人阅读 评论(0) 收藏
- http协议6---响应信息头案例一(请求重定向(相当于超链接跳转页面))
- 第一部分:HTTP协议之请求和响应
- HTTP协议2:请求、响应、缓存
- 【转】:理解HTTP协议的Request/Response(请求响应)模型
- HTTP协议深入学习之请求头域与响应头域详细分析
- http协议请求响应详解
- HTTP协议:pipeline,一个包里有多个请求,一个包里有多个响应
- HTTP协议请求响应过程和HTTPS工作原理
- http协议请求头与响应头相关注解
- http协议请求响应详解
- HTTP协议请求和响应各参数
- http协议5---响应信息的基本格式(实现对请求信息的修改)