Create Handler & Module

  1. Run the Visual Studio
  2. Create a Class Library “HMHandler” --> Change the class to HMHandler.cs
  3. Create a Class Library “HMModule” --> Change the class to HMModule.cs
  4. 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>
  1. Build the solution
  2. Run the Internet Information Services (IIS) Manager
  3. Add a website which Site name is Default Web Site
  4. Physical path is the HMDemo path (eg. D:\HMDemo)
  5. Make sure the managed Pipeline Mode of Default Web Site application pool is Integrated
  6. Copy the scripts folder to D:\HMDemo
  7. Copy the HMModule.dll and HMHandler.dll to D:\HMDemo\bin\
  8. Add IIS_USRS full control to Default Web Site
  9. Run ConfigModules.ps1
  10. Default Web Site --> Handler Mappings Edit Feature Permissions --> Check “Excute”
  11. Default Web Site
  12. Run Windows PowerShell as Administrator
  13. Input Set-ExecutionPolicy RemoteSigned and press <Enter>
  14. Press <Y>
  15. Close Windows PowerShell
  16. 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

  1. Run Windows
    PowerShell
    as Administrator
  2. 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探索的更多相关文章

  1. IIS URL Rewrite Module防盗链规则配置方法

    IIS版本:IIS 7.5 URL Rewrite组件:IIS URL Rewrite Module(http://www.iis.net/downloads/microsoft/url-rewrit ...

  2. IIS URL Rewrite Module的防盗链规则设置

    IIS版本:IIS 7.5 URL Rewrite组件:IIS URL Rewrite Module(http://www.iis.net/downloads/microsoft/url-rewrit ...

  3. 使用微软 URL Rewrite Module 开启IIS伪静态

    原文 使用微软 URL Rewrite Module 开启IIS伪静态 在IIS5和IIS6时代,我们使用URL REWRITING可实现URL重写,使得WEB程序实现伪静态,但默认情况下只能实现.A ...

  4. 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 ...

  5. IIS Express 及 vs2008下使用IIS Express

    介绍 IIS Express 开发 ASP.NET 的应用程序是我的主要工作.当然我会选择最适合的开发环境.客户多属于企业用户,我的开发的选择,多半是 ASP.NET Web Application ...

  6. 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 ...

  7. 在IIS上发布并运行ASP.NET Core

    英文原文地址:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Application ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Android 自学之列表选择框Spinner

    列表选择框(Spinner)与Swing编程里面的Spinner不同,这里的Spinner其实就是一个列表选项框. Spinner是ViewGroup的间接子类,因此他也可作为容器使用. Spinne ...

  2. Linux清空内存缓存

    > /proc/sys/vm/drop_caches

  3. Python 基础【第六篇】字典

    1.字典定义: 字典和列表类似 只是字典标示符用的是字符而列表用的是0开始的数字,字典中每个元素对应一个值 这个元素叫做键(key)键值不能重复 value(值)可以重复 2.字典格式: 格式一: [ ...

  4. [ImportNew]Java中的并发处理

    本文来源:http://www.importnew.com/14506.html 这篇文章讨论了Java应用中并行处理的多种方法.从自己管理Java线程,到各种更好几的解决方法,Executor服务. ...

  5. 分布式算法(一致性Hash算法)

    一.分布式算法 在做服务器负载均衡时候可供选择的负载均衡的算法有很多,包括: 轮循算法(Round Robin).哈希算法(HASH).最少连接算法(Least Connection).响应速度算法( ...

  6. 【转】BUG敏感度的培养

    在我们刚踏入软件测试行业时,不管你是专业的.非专业的,培训出来的还是未培训的.刚进公司时你看着身边的同时报的Bug很多并且大都是严重程度高,自己也很想提高一下,想要提高自己的bug敏感度,建议从下面几 ...

  7. HTML5与CSS3基础教程第八版学习笔记1~6章

    第一章,网页的构造块 网页主要包括三个部分: 1.文本内容(纯文字) 2.对其他文件的引用:图像,音频,视频,样式表文件,js文件 3.标记:对文本内容进行描述并确保引用正确地工作 注:所有这些成分都 ...

  8. 利用Ajax改变发送请求方式

    由于测试的时候需要模拟Head请求,解决办法:先访问要请求的站点,然后在浏览器的控制台下执行如下代码,请求方式就为参数给的值: var xmlHttp; if (window.ActiveXObjec ...

  9. iOS开发——图片轮播图+单选选项

    由于公司开发需要,需要滚动每道评测题, 并且一道评测题单项选择,按钮和文字都可点击选中 (单选比多选复杂一点,但是原理差不多) 1.当初任务紧,代码也没有优化,仅供思路参考,先放几张图 2.代码部分 ...

  10. 启发式搜索 A*算法的OC 实现

    前两天重新学习了下A*算法,上次学习A*算法已经是5年前了,看到网上铺天盖地的A*算法都是C.C++等等其他语言的,就是没有OC 的,所以抽空写了一份.今天太晚了就不说明A*算法的细节了,大家如果想学 ...