Asp.net 2.0 中.aspx请求,即如何生成响应的Html文件
2012-08-14 01:53
585 查看
对于研究过内核的人肯定以为整个.net 最终开始是IISAPIRuntime.ProcessReuqest()然后调用ISAPIRuntime.ProcessRequest(IntPtr ecb, int iWRTyp)
其实还有一种方式,当你在使用.net 时,会自动在C:\WINDOWS\assembly的方件夹再次生成一个WebDev.WebHost
Microsoft.VisualStudio.WebHost.Server.Start()是整个的开始 public Server(int port, string virtualPath, string physicalPath, bool requireAuthentication)
if (applicationInstance is IHttpAsyncHandler)
else
由于Asp.net 2.0东西太多,只说说大体
在Http管道中,HttpApplication是核心
下面是HttpApplication.Init()核心代码如下
if (applicationInstance is IHttpAsyncHandler)
else
返回用户当前是否启用Url重写,再也不用手动处理URL重写啦
UrlMappingsSection urlMappings = RuntimeConfig.GetAppConfig().UrlMappings;
flag = urlMappings.IsEnabled && (urlMappings.UrlMappings.Count > 0);
context.ConfigurationPath = context.Request.ApplicationPathObject;
using (HttpContextWrapper wrapper = new HttpContextWrapper(context))
HttpApplication.BeginProcessRequest()时会调用HttpApplication.ResumeSteps()
就是对上面IExecutionStep进行依次的处理
在MapHandlerExecutionStep时,会根据如何配置取出对应的工厂
Asp.net 2.0 根 Web.config
<httpHandlers>
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True" />
</httpHandlers>
今天只谈.aspx
上面都是大家知道的,没什么意思啦
咱来点有意思的
搞.net 的人都知道.aspx会使用PageHandlerFactory .GetHandlerHelper()返回一个IHttpHandler
大家有没有发现
GethandlerHelper() 里有下面的方法
Page page = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page), context, true, true) as Page;
internal static object CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, bool allowCrossApp, bool noAssert)
其实这个Page是一个BuildRequest,asp.net 2.0在第一次请求时会对dll再一次的编译,
举个例子你写了一个webForm1.aspx,里面有一个Button,
此时.net 会从webForm1.axp派生出一个新的类
如下
//[CompilerGlobalScope]
//public class webform1_aspx : WebForm1, IRequiresSessionState, IHttpHandler
//{
// // Fields
// private static object __fileDependencies;
// private static bool __initialized;
..
// protected override void FrameworkInitialize()
// {
// base.FrameworkInitialize();
// this.__BuildControlTree(this); //此处创建控件树,(CtronlBuilder的作用在这里!!!!!!!!!!!)
// base.AddWrappedFileDependencies(__fileDependencies);
// base.Request.ValidateInput();
// }
// public override int GetTypeHashCode()
// {
// return 0x579d6af1;
// }
// public override void ProcessRequest(HttpContext context)
// {
// base.ProcessRequest(context);
// }
//}
当您请求WebForm1时
ITypedWebObjectFactory.GetType() 是BuildResultCompiledTemplateType它是BuildResultCompiledType的实现
ITypedWebObjectFactory.CreateInstance()就是BuildResultCompiledType.CreateInstance()
它会使用
ObjectFactoryCodeDomTreeGenerator.GetFastObjectCreationDelegate(this.ResultType);
在新生成的程序集中Asp命名空间下有这个类呀,直接new webform1_aspx ()
也就是说,此时你请求webform1,实际调用的是新生所在webform1_aspx ()
下面会依次执行
CallHandlerExecutionStep 处理输出流
CallFilterExecutionStep()调用webform1_aspx.ProcessRequest()
...
下面说一下,你请求的webForm1_aspx是如何转成html的即,Render时的顺序:
原理如下图
其实还有一种方式,当你在使用.net 时,会自动在C:\WINDOWS\assembly的方件夹再次生成一个WebDev.WebHost
Microsoft.VisualStudio.WebHost.Server.Start()是整个的开始 public Server(int port, string virtualPath, string physicalPath, bool requireAuthentication)
if (applicationInstance is IHttpAsyncHandler)
else
由于Asp.net 2.0东西太多,只说说大体
在Http管道中,HttpApplication是核心
下面是HttpApplication.Init()核心代码如下
if (applicationInstance is IHttpAsyncHandler)
else
返回用户当前是否启用Url重写,再也不用手动处理URL重写啦
UrlMappingsSection urlMappings = RuntimeConfig.GetAppConfig().UrlMappings;
flag = urlMappings.IsEnabled && (urlMappings.UrlMappings.Count > 0);
context.ConfigurationPath = context.Request.ApplicationPathObject;
using (HttpContextWrapper wrapper = new HttpContextWrapper(context))
HttpApplication.BeginProcessRequest()时会调用HttpApplication.ResumeSteps()
就是对上面IExecutionStep进行依次的处理
在MapHandlerExecutionStep时,会根据如何配置取出对应的工厂
Asp.net 2.0 根 Web.config
<httpHandlers>
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True" />
</httpHandlers>
今天只谈.aspx
上面都是大家知道的,没什么意思啦
咱来点有意思的
搞.net 的人都知道.aspx会使用PageHandlerFactory .GetHandlerHelper()返回一个IHttpHandler
大家有没有发现
GethandlerHelper() 里有下面的方法
Page page = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page), context, true, true) as Page;
internal static object CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, bool allowCrossApp, bool noAssert)
其实这个Page是一个BuildRequest,asp.net 2.0在第一次请求时会对dll再一次的编译,
举个例子你写了一个webForm1.aspx,里面有一个Button,
此时.net 会从webForm1.axp派生出一个新的类
如下
//[CompilerGlobalScope]
//public class webform1_aspx : WebForm1, IRequiresSessionState, IHttpHandler
//{
// // Fields
// private static object __fileDependencies;
// private static bool __initialized;
..
// protected override void FrameworkInitialize()
// {
// base.FrameworkInitialize();
// this.__BuildControlTree(this); //此处创建控件树,(CtronlBuilder的作用在这里!!!!!!!!!!!)
// base.AddWrappedFileDependencies(__fileDependencies);
// base.Request.ValidateInput();
// }
// public override int GetTypeHashCode()
// {
// return 0x579d6af1;
// }
// public override void ProcessRequest(HttpContext context)
// {
// base.ProcessRequest(context);
// }
//}
当您请求WebForm1时
ITypedWebObjectFactory.GetType() 是BuildResultCompiledTemplateType它是BuildResultCompiledType的实现
ITypedWebObjectFactory.CreateInstance()就是BuildResultCompiledType.CreateInstance()
它会使用
ObjectFactoryCodeDomTreeGenerator.GetFastObjectCreationDelegate(this.ResultType);
在新生成的程序集中Asp命名空间下有这个类呀,直接new webform1_aspx ()
也就是说,此时你请求webform1,实际调用的是新生所在webform1_aspx ()
下面会依次执行
CallHandlerExecutionStep 处理输出流
CallFilterExecutionStep()调用webform1_aspx.ProcessRequest()
...
下面说一下,你请求的webForm1_aspx是如何转成html的即,Render时的顺序:
原理如下图
相关文章推荐
- Asp.net 2.0 中.aspx请求,即如何生成响应的Html文件(原创)
- 摘要:了解 ASP.NET 2.0 中的用于生成自定义数据绑定控件的工具是如何演变的
- ASP.NET Core真实管道详解[2]:Server是如何完成针对请求的监听、接收与响应的【上】
- 开发ASP.NET 2.0 Web应用程序时如何将App_Code文件夹中的共享代码配置生成多个Dll
- 开发ASP.NET 2.0 Web应用程序时如何将App_Code文件夹中的共享代码配置生成多个Dll
- asp.net core生成路由连接,请求参数如何获取和模型绑定
- 开发ASP.NET 2.0 Web应用程序时如何将App_Code文件夹中的共享代码配置生成多个Dll
- 在ASP.NET 2.0中,有时候需要对ASP.NET生成的HTML代码进行处理,或者是保存成静态文件。ASP.NET 提供了直接将请求保存成文件的方法:HttpRequest.SaveAs方法。下面这个方法就是在ASP.NET 2.0中得到ASP.NET
- 学习ASP.NET Core, 怎能不了解请求处理管道[3]: 自定义一个服务器感受一下管道是如何监听、接收和响应请求的
- 如何测量并报告ASP.NET Core Web API请求的响应时间
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码(转自孟宪会之精彩世界)
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- Self Host模式下的ASP. NET Web API是如何进行请求的监听与处理的?
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- ASP.NET 2.0: 在使用web.sitemap时,如何实现本地化
- 如何在asp.net中用C#自动生成透明的GIF图片
- 在asp.net中如何从视频文件中抓取一桢并生成图像文件
- ASP.NET 2.0如何实现URL映射教程