易截截图软件、单文件、免安装、纯绿色、仅160KB

微软企业库5.0学习笔记(10)ASP.NET模块依赖注入

    您可以使用HTTP模块,一个到ASP.NET HttpApplicationState类的扩展,在Global.asax编写代码强制ASP.NET在每一个页面请求时自动注入依赖的对象,就像在ASP.NET Web窗体应用程序中讨论的一样.
    下列方法显示了一个合适的方法能够获取PreRequestHandlerExecute事件将它自己注入到ASP.NET的执行流水线,在每个页面请求中通过容器的BuildUp方法运行Http模块,并获取OnPageInitComplete事件。当OnPageInitComplete执行时模块代码按照所有的控件树运行,并通过容器的BuildUp方法处理每个控件。
    BuildUp方法获取已经存在的对象实例,处理并填充类的依赖,返回实例。如果没有依赖则返回最初的实例。
     using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using Microsoft.Practices.Unity;
namespace Unity.Web
{
public class UnityHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += OnPreRequestHandlerExecute;
}
public void Dispose() { }
private void OnPreRequestHandlerExecute(object sender, EventArgs e)
{
IHttpHandler currentHandler = HttpContext.Current.Handler;
HttpContext.Current.Application.GetContainer().BuildUp(
currentHandler.GetType(), currentHandler);
// User Controls are ready to be built up after page initialization is complete
var currentPage = HttpContext.Current.Handler as Page;
if (currentPage != null)
{
currentPage.InitComplete += OnPageInitComplete;
}
}
// Build up each control in the page's control tree
private void OnPageInitComplete(object sender, EventArgs e)
{
var currentPage = (Page)sender;
IUnityContainer container = HttpContext.Current.Application.GetContainer();
foreach (Control c in GetControlTree(currentPage))
{
container.BuildUp(c.GetType(), c);
}
context.PreRequestHandlerExecute -= OnPreRequestHandlerExecute;
}
// Ge


相关文档:

ASP.NET页面传值_第一篇_概述


方法
数据量
生命期
作用域
位置
Application
任意大小
整个应用程序
所有用户
服务端
Cache
任意大小
根据需要设定
所有用户
服务端
Cookie
简单数据
根据需要设定
单个用户
客户端
Session
简单数据
用户活动时间+延迟时间(20分钟)
单个用户
服务端
Web.Config
极少改变简单数据
直到改变配 ......

ASP.NET页面传值_第四篇_Session

例一:
+++ 修改Global.asax文件:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{  }
void Application_End(object sender, EventArgs e)
{  }
void Application_Error(object sender, EventArgs e)
{  }
void ......

ASP.NET页面传值_第五篇_Application

+++ 修改Global.asax文件:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
  Application["count"] = 0;
}
void Application_End(object sender, EventArgs e)
{  }
void Application_Error(object sender, EventArgs ......

asp.net 打印 拒绝访问

参考 http://topic.csdn.net/t/20040510/19/3051316.html
      开始
      运行
      dcomcnfg
      组件服务一项中选择Dcom配置,找到Microsoft   excel应用程序,察看属性
      安全选项卡中,启动权限和访问权 ......

ASP.NET中,几段播放器的代码

第一种播放器代码:
<object title="dvubb" align="middle" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" class="object" id="MediaPlayer" width="480" height="360">
<param name="AUTOSTART" value="true"/>
<param name="ShowStatusBar" value="-1"/>
<param name="Filename" va ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号