asp.net web 项目 针对aspx和ashx的 IHttpHandlerFactory 开发
ASP.NET Framework处理一个Http Request的流程:
HttpRequest-->inetinfo.exe-->ASPNET_ISAPI.dll-->ASPNET_WP.exe-->HttpRuntime-->HttpApplication Factory-->HttpApplication-->HttpModule-->HttpHandler Factory-->HttpHandler-->HttpHandler.ProcessRequest()
参考:https://www.cnblogs.com/sunliyuan/p/5876253.html
参考:https://www.cnblogs.com/firstyi/archive/2008/05/07/1187274.html
实现自定义的HandlerFactory
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
IHttpHandler handler = factory.GetHandler(context, requestType, url, pathTranslated); //执行一些其它操作
Execute(handler); return handler;
}
web.config 配置如下:
<system.web>
<httpHandlers>
<add verb="*" path="*.aspx" type="HttpHandle.MyHandlerFactory, HttpHandle"/>
</httpHandlers>
</system.web>
但是在新版本vs会有托管管道不适用的报错。
检测到在集成的托管管道模式下不适用的 ASP.NET 设置的解决方法
请参考该文章:https://www.cnblogs.com/wanglg/p/3515765.html
改动点: <system.web> <httpHandlers>
<add verb="*" path="*.aspx" type="HttpHandle.MyHandler, HttpHandle"/>
</httpHandlers> </system.web> 改为: <system.webServer>
<handlers>
<add name="MyHandlerFactory" verb="*" path="*.aspx" type="WebForm.Http.MyHandlerFactory, WebForm.Http"/>
</handlers>
</system.webServer>
以上是针对aspx。
ashx页面要对factory类稍作改动。
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
//一些拦截处理 var a = BuildManager.CreateInstanceFromVirtualPath(context.Request.RawUrl, typeof(IHttpHandler));
return a as IHttpHandler;
}
通过这个类我们可以更加了解.net对http的处理流程,也可以扩展出许多更有趣的实现。例如在这里对aspx、ashx页面注入一些方法^_^
asp.net web 项目 针对aspx和ashx的 IHttpHandlerFactory 开发的更多相关文章
- VS2015 ASP.NET5 Web项目
VS2015 ASP.NET5 Web项目结构浅析 前言 本文个人同步博客地址http://aehyok.com/Blog/Detail/76.html 在安装好VS2015之后,一直想看看新版本 ...
- 在 Visual Studio 2013 中创建 ASP.NET Web 项目(0):专题导航 [持续更新中]
写在前面的话 随着 Visual Studio 2013 的正式推出,ASP.NET 和 Visual Studio Web 开发工具 也发布了各自的最新版本. 新版本在构建 One ASP.NET ...
- 在 Visual Studio 2013 中创建 ASP.NET Web 项目(1):概述 - 创建 Web 应用程序项目
注:本文是“在 Visual Studio 2013 中创建 ASP.NET Web 项目”专题的一部分,详情参见 专题导航 . 预备知识 本专题适用于 Visual Studio 2013 及以上版 ...
- ASP.NET Web项目发布选项:“允许更新此预编译站点” 详解
目录 #使用visual studio 发布web项目 #"允许更新此预编译站点" 选项的意义 1.选中 "允许更新此预编译站点" 2.不选中 "允许 ...
- 在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用
由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.NET Web API 的书籍少之又少(我们看到的相关内容往往是某本介绍ASP.NET M ...
- ASP.Net Web Form<一> aspx文件编译及呈现
对比复习下JSP 1.jsp的本质是Servlet ,会在第一次被访问时会被翻译成一个类文件,从此对这个页面的访问都是由这个类文件执行后进行输出. aspx 本质是IHttpHandler 2.jsp ...
- asp.net Web项目中使用Log4Net进行错误日志记录
使用log4net可以很方便地为应用添加日志功能.应用Log4net,开发者可以很精确地控制日志信息的输出,减少了多余信息,提高了日志记录性能.同时,通过外部配置文件,用户可以不用重新编译程序就能 ...
- ASP.NET MVC 项目中 一般处理程序ashx 获取Session
1-在 aspx和aspx.cs中,都是以Session["xxx"]="aaa"和aaa=Session["xxx"].ToString( ...
- 配置Asp.Net Web项目NLog配置文件的位置
在使用NLog在asp.net项目中发现,如果想单独配其配置文件的位置时没有像Log4Net的特性配置方案,可以使其提供的 XmlLoggingConfiguration类来初始化: 见:https: ...
随机推荐
- windows及linux环境下修改pip的默认镜像源的方法
1. 在windows环境下 临时修改 使用清华大学的源安装numpy包. pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple ...
- pdfium sdk调用方式
FPDF_InitLibrary(NULL); FPDF_CreateNewDocument(); FPDF_DestroyLibrary();
- clickhouse数据库
https://www.jianshu.com/p/a5bf490247ea https://www.cnblogs.com/davygeek/p/8018292.html 开源分布式数据库 htt ...
- MySQL添加CSV文件中的数据
一.MySQL添加csv数据 此问题是前几天整理数据的时候碰到的,数据存在 CSV文件中(200多万记录),通过python 往数据库中导入太慢了,后来使用MySQL 中自带的命令 LOAD DATA ...
- 201871010108-高文利《面向对象程序设计(java)》第十三周学习总结
项目 内容 这个作业属于哪个课程 <任课教师博客主页链接> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 <作业链接地址> ht ...
- [POJ3107]Godfather
题目描述 Description Last years Chicago was full of gangster fights and strange murders. The chief of th ...
- PATB1033 旧键盘打字 (20 分)
一.技术总结 使用字符数组出现段错误即char str[];改成string str:后问题解决.以后尽量使用C++中的string 使用cin>>,出现答案错误,原因可能是在输入是有空格 ...
- Vue组件的操作-自定义组件,动态组件,递归组件
作者 | Jeskson 来源 | 达达前端小酒馆 v-model双向绑定 创建双向数据绑定,v-model指令用来在input,select,checkbox,radio等表单控件.v-model指 ...
- [LeetCode] 214. Shortest Palindrome 最短回文串
Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] 96. Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example ...