IIS Handler and Module探索
Create Handler & Module
- Run the Visual Studio
- Create a Class Library “HMHandler” --> Change the class to HMHandler.cs
- Create a Class Library “HMModule” --> Change the class to HMModule.cs
- Create an ASP.NET Web Application “HMDemo” --> Add a Default.aspx page, to test the handler and module, remember the physical path of the site. (e.g. D:\HMDemo)
The structure of solution as below
1. Add code in HMHandler.cs as below
using System; using System.Web; namespace HMHandler
{
public class HMHandler : IHttpHandler
{
public bool IsReusable
{
get
{
return true;
}
} public void ProcessRequest(HttpContext context)
{
DateTime dt; String useUtc = context.Request.QueryString["utc"]; if (!String.IsNullOrEmpty(useUtc) && useUtc.Equals("true"))
{
dt = DateTime.UtcNow;
}
else
{
dt = DateTime.Now;
}
context.Response.Write(
String.Format("<h1>{0}</h1>",
dt.ToLongTimeString()
));
}
}
}
2. Update the code in HMModule
using System;
using System.Text;
using System.Web;
namespace HMModule
{
public class HMModule : IHttpModule
{
public void Dispose()
{
//throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
context.AuthenticateRequest += Context_AuthenticateRequest;
}
private void Context_AuthenticateRequest(object sender, EventArgs e)
{
try
{
//Get http application
HttpApplication app = sender as HttpApplication;
//Get authorization
var authorization = app.Request.Headers["Authorization"];
//Remove the "Basic "
var authChar = authorization.Remove(, );
var authBytes = Convert.FromBase64String(authChar);
var authString = Encoding.UTF8.GetString(authBytes);
//Reset the authorization
app.Request.Headers.Set("Authorization", "Basic YWR2ZW50XHNmZW5nOk1lbmcxMjMkJV4=");
app.Response.Write("<h1>Module_Authentication is passed</h1>");
}
catch (Exception)
{
}
}
}
}
3. Update the Defualt.aspx.cs
using System; namespace HMDemo
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("hello from default page</br>");
}
}
}
4. Update the web.config as below
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6"/>
</system.web>
<system.webServer>
<handlers accessPolicy="Read, Execute, Script">
<add name="HMHandler" path="*.dll" verb="*" type="HMHandler.HMHandler" resourceType="File" requireAccess="Execute" preCondition="integratedMode"/>
</handlers>
<modules>
<add name="HMModule" type="HMModule.HMModule" />
</modules>
</system.webServer>
</configuration>
- Build the solution
- Run the Internet Information Services (IIS) Manager
- Add a website which Site name is Default Web Site
- Physical path is the HMDemo path (eg. D:\HMDemo)
- Make sure the managed Pipeline Mode of Default Web Site application pool is Integrated
- Copy the scripts folder to D:\HMDemo
- Copy the HMModule.dll and HMHandler.dll to D:\HMDemo\bin\
- Add IIS_USRS full control to Default Web Site
- Run ConfigModules.ps1
- Default Web Site --> Handler Mappings Edit Feature Permissions --> Check “Excute”
- Default Web Site
- Run Windows PowerShell as Administrator
- Input Set-ExecutionPolicy RemoteSigned and press <Enter>
- Press <Y>
- Close Windows PowerShell
- Run Windows PowerShell Modules as Administrator
Build IIS
Unlock Web Global Modules
In Windows Server 2008 r2
$modules = Get-WebGlobalModule $modules $count = $modules.Count for($i=1;$i -le $count; $i++)
{
C:\Windows\System32\inetsrv\appcmd.exe set module $modules[$i].Name /lockItem:true
}
In Windows Server 2012 r2
- Run Windows
PowerShell as Administrator - Run the ConfigModules.ps1"
Get Web Global Modules"
$modules = Get-WebGlobalModule $modules $count = $modules.Count for($i=1;$i -le $count; $i++)
{
C:\Windows\System32\inetsrv\appcmd.exe set module $modules[$i].Name /lockItem:true
}
Test
Logon and the planned results as below

IIS Handler and Module探索的更多相关文章
- IIS URL Rewrite Module防盗链规则配置方法
IIS版本:IIS 7.5 URL Rewrite组件:IIS URL Rewrite Module(http://www.iis.net/downloads/microsoft/url-rewrit ...
- IIS URL Rewrite Module的防盗链规则设置
IIS版本:IIS 7.5 URL Rewrite组件:IIS URL Rewrite Module(http://www.iis.net/downloads/microsoft/url-rewrit ...
- 使用微软 URL Rewrite Module 开启IIS伪静态
原文 使用微软 URL Rewrite Module 开启IIS伪静态 在IIS5和IIS6时代,我们使用URL REWRITING可实现URL重写,使得WEB程序实现伪静态,但默认情况下只能实现.A ...
- IIS FTP Server Anonymous Writeable Reinforcement, WEBDAV Anonymous Writeable Reinforcement(undone)
目录 . 引言 . IIS 6.0 FTP匿名登录.匿名可写加固 . IIS 7.0 FTP匿名登录.匿名可写加固 . IIS >= 7.5 FTP匿名登录.匿名可写加固 . IIS 6.0 A ...
- IIS Express 及 vs2008下使用IIS Express
介绍 IIS Express 开发 ASP.NET 的应用程序是我的主要工作.当然我会选择最适合的开发环境.客户多属于企业用户,我的开发的选择,多半是 ASP.NET Web Application ...
- IIS 7.0, ASP.NET, pipelines, modules, handlers, and preconditions
1.0 What is the IIS Pipeline Conceptually, the IIS pipeline is a state machine with the following st ...
- 在IIS上发布并运行ASP.NET Core
英文原文地址:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Application ...
- ASP.NET IIS Registration Tool (Aspnet_regiis.exe)
IIS Version Special cases for 32-bit versions of Aspnet_regiis.exe 6.0 You can run the 32-bit versio ...
- IIS URL Rewriting and ASP.NET Routing
IIS URL Rewriting and ASP.NET Routing With the release of the URL Rewrite Module for IIS and the inc ...
随机推荐
- Unix 网络编程(2)——TCP API
TCP C/S套接口函数一般调用过程及基本函数 如上图所示的TCP连接的基本过程.一般来说,服务器先于客户端运行,服务器程序运行的基本过程是: socket()函数创建服务器段socket. bind ...
- aggregation 详解4(pipeline aggregations)
概述 管道聚合处理的对象是其它聚合的输出(桶或者桶的某些权值),而不是直接针对文档. 管道聚合的作用是为输出增加一些有用信息. 管道聚合大致分为两类: parent 此类聚合的"输入&quo ...
- posix thread互斥量
互斥量 互斥量(Mutex)是“mutual exclusion”的缩写.互斥量是实现线程同步,和保护同时写共享数据的主要方法.使用互斥量的典型顺序如下:1. 创建和初始一个互斥量 2. 多个线程尝试 ...
- TamperData火狐插件启用
今天第一次在准备学习sqlmap的时候看到有人使用了这个TamperData火狐的插件,所以我也安装来看看,光是安装了,但是重启浏览器之后不知道怎么启用,得不到想要的运行界面,所以在这里记录一下,为自 ...
- [转]在.Net中使用Oracle的表类型和对象类型
本文转自:http://www.cnblogs.com/studyzy/archive/2010/10/13/1850161.html 在一般的数据存取操作过程中,如果要对一个主表和对应的子表进行插入 ...
- Activiti 工作流会签开发设计思路
http://man1900.iteye.com/blog/1607753 在流程业务管理中,任务是通常都是由一个人去处理的,而多个人同时处理一个任务,这种任务我们称之为会签任务.这种业务需求也很常见 ...
- web app开发中 iPhone、iPad默认按钮样式问题
webapp开发过程中,用html5+css3很方便,而且可以很方便的编译到Android ios等不同平台,但是ios需要单独处理一下,不然会出现一些想象不到的问题.下面就介绍一下各种问题的解决方法 ...
- MFC程序实现窗口分割,视图快捷插入控件和插入列表
将视图中插入列表: 1.创建一个MFC应用程序,在MFC Wizard中,生成的类选项,如图 2.选择CListView作为基类 3.在CXXView.cpp(XX为你的程序名)重写虚函数OnInit ...
- 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记1 IOS8概述
首先感谢网易公开课和SwiftV课堂的朋友们辛苦翻译,这个系列是我学习斯坦福IOS8公开课的个人心得体会和笔记,希望能给大家带来启发. 首先我们要知道IOS系统中的结构情况,从贴近硬件的底层到贴近用户 ...
- 纯代码添加约束条件(Auto Layout)
Auto Layout 是一种基于约束的.描述性的布局系统.也就是使用约束条件来描述布局,View的Frame会根据这些描述来进行计算. 在iOS6.0以后加入了一个新类: NSLayoutConst ...