拦截对该服务器所有的http请求
一:拦截对该服务器所有的http请求。
在config 中加,
<system.webServer> <modules> <add name="HttpAuthvalid" type="YGPT.Country.Auth.HttpAuthvalid"/> </modules> </system.webServer>
然后每次http请求都先进这个类(这个类需要继承
System.Web.IHttpModule
)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
namespace YGPT.Country.Auth
{
/// <summary>
/// 权限验证
/// </summary>
public class HttpAuthvalid : System.Web.IHttpModule
{
public void Dispose()
{
//此处放置清除代码。
}
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(SystemProcess);
}
/// <summary>
/// 系统访问处理 (系统资源加载,权限验证等)
/// </summary>
void SystemProcess(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;// 获取应用程序
string url = application.Request.Url.AbsolutePath.ToString();// 获取Url
if (url == "/setToken")//如果是设置令牌
{
if (!string.IsNullOrEmpty(application.Context.Request["param"]))
{
HttpCookie cookie = application.Request.Cookies["YGPT_SESSIONID"];
if (cookie == null)
{
cookie = new HttpCookie("YGPT_SESSIONID");
}
//组合重置cookie 令牌
cookie.Value =
application.Context.Request["param"] +
YGPT.Country.Auth.EncryptDecrypt.AESEncrypt(YGPT.Country.Auth.Config.DesToValue + DateTime.Now.ToString("yyyyMMdd"), Config.DecryptKey);
cookie.HttpOnly = true;
cookie.Expires = DateTime.Now.AddDays();
application.Response.AppendCookie(cookie);
application.Response.Write("JsonpHandler({\"result\":\"1\"})");//成功
application.Response.End();
return;
}
else
{
application.Response.Write("JsonpHandler({\"result\":\"0\"})");//失败
application.Response.End();
return;
}
}
if (application.Request.Cookies["YGPT_SESSIONID"] == null || string.IsNullOrEmpty(application.Request.Cookies["YGPT_SESSIONID"].Value))
{
application.Response.Redirect(YGPT.Country.Auth.Config.TimeOutUrl);//跳转到超时页面
application.Response.End();
return;
}
//string PermisWeburl = System.Configuration.ConfigurationManager.AppSettings["PermisWeburl"];
//string[] pweburls = PermisWeburl.Split(',');
//for (int i = 0; i < pweburls.Length; i++)
//{
// if (url.Contains(pweburls[i]))//登录超时 没权限不做验证
// {
// return;
// }
//}
if (System.Configuration.ConfigurationManager.AppSettings["workingmode"] != "deve")
{
)//页面权限
{
User myuser = CurrentUser.GetUser();
if (myuser.UserID.ToUpper() == "ADMIN")
{
return;
}
/*验证页面权限*/
YGPT.Country.Auth.SystypeValue sv = new SystypeValue();
sv.SysType = Config.SystemType;
sv.ValueName = url;
if (myuser.PageHandButton.PageCollect.Contains(sv))
{
///跳转到无权限页面
CurrentUser.Goto_NoPermission();
}
}
)//http请求权限
{
User myuser = CurrentUser.GetUser();
application.Response.ContentType = "text/plain";
application.Response.Buffer = true;
application.Response.ExpiresAbsolute = DateTime.Now.AddDays(-);
application.Response.AddHeader("pragma", "no-cache");
application.Response.AddHeader("cache-control", "");
application.Response.CacheControl = "no-cache";
if (CurrentUser.Userid.ToUpper() == "ADMIN")
{
return;
}
//验证请求权限
////数据处理必须包含 req 参数
if (string.IsNullOrEmpty(application.Context.Request["req"]))
{
///跳转到无权限页面
application.Response.Write(JsonConvert.SerializeObject("NoPermission"));
application.Response.End();
}
string UrlAndQu = url + "?req=" + application.Context.Request["req"];
YGPT.Country.Auth.SystypeValue sv = new SystypeValue();
sv.SysType = Config.SystemType;
sv.ValueName = UrlAndQu;
if (myuser.PageHandButton.PageCollect.Contains(sv))
{
///返回无权限信息
application.Response.Write(JsonConvert.SerializeObject("NoPermission"));
application.Response.End();
return;
}
}
}
}
public void OnLogRequest(Object source, EventArgs e)
{
//可以在此放置自定义日志记录逻辑
}
}
}
拦截对该服务器所有的http请求的更多相关文章
- 单点登录CAS使用记(五):cas-client不拦截静态资源以及无需登录的请求。
一.问题在哪? 在配置cas-client中,有这么一段配置: <filter> <filter-name>CAS Filter</filter-name> < ...
- 关于wcf异常异常信息:由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribut
异常信息:由于内部错误,服务器无法处理该请求.有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribut ...
- C# 向Http服务器送出 POST 请求
//向Http服务器送出 POST 请求 public string m_PostSubmit(string strUrl,string strParam) { string strResult = ...
- 接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。
[2015/8/5 19:28:49]错误信息:接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误.这可能是由于服务终结点绑定 ...
- 解决WCF“接收对 http://xxx.svc 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致"
最近在工作中新加了一个接口,本地调试的时候,直接抛出“接收对 http://xxx.svc 的 HTTP 响应时发生错误.这可能是由于服务终结点绑定未使用 HTTP 协议造成的.这还可能是由于服务器中 ...
- 基于Ryu的服务器实现及相关请求访问处理
基于Ryu的服务器实现及相关请求访问处理 前言及问题描述 近期又遇到了一个非常棘手的问题,由于Ryu是通过Python语言开发的,通过Ryu的wsgi的方式建立服务器,无法解析PHP,通过多次方法解决 ...
- jmeter ---测试TCP服务器/模拟发送TCP请求
jmeter测试TCP服务器/模拟发送TCP请求 jmeter测试TCP服务器,使用TCP采样器模拟发送TCP请求. TCP采样器:打开一个到指定服务器的TCP / IP连接,然后发送指定文本并等待响 ...
- 4xx错误的本质:服务器已经接收到请求
4xx错误的本质:服务器已经接收到请求, 路径错误! { URL: http://10.100.138.32:8046/3-0/app/account/maxin } { status code: 4 ...
- 跟着大彬读源码 - Redis 3 - 服务器如何响应客户端请求?(下)
继续我们上一节的讨论.服务器启动了,客户端也发送命令了.接下来,就要到服务器"表演"的时刻了. 1 服务器处理 服务器读取到命令请求后,会进行一系列的处理. 1.1 读取命令请求 ...
随机推荐
- nodejs的某些api~(三)net模块
net模块和http模块是node最重要的两个模块,前者是基于TCP的封装,后者的本质也是TCP.他们通过 tcp通信,建立一个可以收发消息的web服务器.我在写的作品里面用的express也是封装的 ...
- Zabbix监控服务器硬盘状态
安装Iptables服务: [root@localhost /]# yum install iptables-services [root@localhost /]# vim /etc/sysconf ...
- 区块链使用Java,以太坊 Ethereum, web3j, Spring Boot
Blockchain is one of the buzzwords in IT world during some last months. This term is related to cryp ...
- golang go语言通道类型的通道示例 通道的通道
几点注意:go的无缓存通道 通道make 创建后,即使里面是空的,也可以取里面内容.但是程序会被阻塞. 通道的规则是没人取,是不能往里面放的.放的线程会阻塞. 最外层的requestChan相当于一个 ...
- log4j2 自定义配置文件,java载入
http://logging.apache.org/log4j/2.x/faq.html#separate_log_files How do I reconfigure log4j2 in code ...
- 面试篇——mysql
背景:在面试过程中发现很多公司对sql查询有要求,虽然不高,但是简单常见的sql查询必须熟练的掌握,否则一面都无法通过,痛定思痛,必须要深入了解下!!! 注释符号 面试题1 查询没有成绩的学生信息 参 ...
- win32: 静态控件(Static) - SS_NOTIFY - 响应事件
SS_NOTIFY 在缺省情况下,静态控件是不响应鼠标事件的.只有在设置该风格后,当用户单击静态 控件时,静态控件才向父窗口发送STN_CLICKED通知 -> WM_COMMAND. 2014 ...
- logistics回归简单应用(二)
警告:本文为小白入门学习笔记 网上下载的数据集链接:https://pan.baidu.com/s/1NwSXJOCzgihPFZfw3NfnfA 密码: jmwz 不知道这个数据集干什么用的,根据直 ...
- 位掩码(BitMask)的介绍与使用
一.前言 位运算在我们实际开发中用得很少,主要原因还是它对于我们而言不好读.不好懂.也不好计算,如果不经常实践,很容易就生疏了.但实际上,位运算是一种很好的运算思想,它的优点自然是计算快,代码更少. ...
- JavaScript时间日期函数
//随机数生成器Math.random() 装换为整数parseInt() 日期时间函数(需要用变量调用):var b = new Date(); //获取当前时间b.getTime() //获取时间 ...