https://msdn.microsoft.com/en-us/library/aa719858(v=vs.71).aspx

http://www.cnblogs.com/jimmyzhang/archive/2007/11/25/971878.html

web.config

<configuration>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<add name="MyRedirect" type="MyRedirect.MyRedirect, MyRedirect" />
</modules>
</system.webServer>
</configuration>

创建类库 编译该类   把生成的DLL直接放到bin  然后修改config   OK

using System;
using System.Collections;
using System.Web; namespace MyRedirect
{
public class MyRedirect : IHttpModule
{
public String ModuleName
{
get { return "MyRedirect"; }
} // In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
} // Your BeginRequest event handler.
private void Application_BeginRequest(Object source, EventArgs e)
{ HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
//context.Response.Redirect("http://www.baidu.com");
//context.Response.Write("<h1><font color=red>test</font></h1><hr>");
string accessUrl = System.Configuration.ConfigurationManager.AppSettings["AccessUrl"];
string redirectUrl = System.Configuration.ConfigurationManager.AppSettings["RedirectUrl"];
//context.Response.Write("<h1><font color=red>"+ accessUrl + "</font></h1><hr>");
//context.Response.Write("<h1><font color=red>"+ redirectUrl + "</font></h1><hr>");
if (context.Request.Url.Host == accessUrl)
{ context.Response.Redirect(redirectUrl);
} } public void Dispose()
{
}
}
}

相关问题:

http://www.cnblogs.com/xiaoshi657/p/6515492.html

Asp.Net 自定义 httpmodel 中间件 管道的更多相关文章

  1. ASP.Net 自定义HttpModule注册管道事件

    背景: 一个请求在到达处理器时 可能需要做很多重复的工作 比如使用固定的算法推算出用户id 角色   如果在应用程序各处做重复解析 会产生大量代码冗余 还有能想到的诸如记录访问者 应用日志 统计流量 ...

  2. 如何传递参数给ASP.NET Core的中间件(Middleware)

    问题描述 当我们在ASP.NET Core中定义和使用中间件(Middleware)的时候,有什么好的办法可以给中间件传参数吗? 解决方案 在ASP.NET Core项目中添加一个POCO类来传递参数 ...

  3. 自定义ASP.NET Core日志中间件

    这个日志框架使用的是ASP.NET Core的NLog,用来记录每次请求信息和返回信息. 1.首先创建一个Web应用项目,我选择的是MVC模板: 2.使用NuGet添加Microsoft.Extens ...

  4. asp.net core 自定义异常处理中间件

    asp.net core 自定义异常处理中间件 Intro 在 asp.net core 中全局异常处理,有时候可能不能满足我们的需要,可能就需要自己自定义一个中间件处理了,最近遇到一个问题,有一些异 ...

  5. 【3】Asp.Net Core2.2新版管道处理模型

    [前言] 上一篇完成了Asp.Net Core 2.2项目的一个最简单功能的添加,从控制器-视图-实体轻松交互了一下,感觉跟之前的MVC没啥差别!但这些都是在组件封装的基础上完成的,在Core里面,其 ...

  6. ASP.NET Core之中间件

    本文翻译自:http://www.tutorialsteacher.com/core/aspnet-core-middleware 基本概念 ASP.NET Core引入了中间件的概念,中间件是在AS ...

  7. asp.net core mvc 中间件之WebpackDevMiddleware

    asp.net core mvc 中间件之WebpackDevMiddleware WebpackDevMiddleware中间件主要用于开发SPA应用,启用Webpack,增强网页开发体验.好吧,你 ...

  8. ASP.NET Core 中的管道机制

    首先,很感谢在上篇文章 C# 管道式编程 中给我有小额捐助和点赞的朋友们,感谢你们的支持与肯定.希望我的每一次分享都能让彼此获得一些收获,当然如果我有些地方叙述的不正确或不当,还请不客气的指出.好了, ...

  9. 如何在 asp.net core 的中间件中返回具体的页面

    前言 在 asp.net core 中,存在着中间件这一概念,在中间件中,我们可以比过滤器更早的介入到 http 请求管道,从而实现对每一次的 http 请求.响应做切面处理,从而实现一些特殊的功能 ...

随机推荐

  1. BZOJ5450: 轰炸(水题,Tarjan缩点求最长路)

    5450: 轰炸 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 43  Solved:18[Submit][Status][Discuss] Desc ...

  2. HDU5880 Family View ac自动机第二题

    Steam is a digital distribution platform developed by Valve Corporation offering digital rights mana ...

  3. CODEVS3013 单词背诵 【Hash】【MAP】

    CODEVS3013 单词背诵 题目描述 Description 灵梦有n个单词想要背,但她想通过一篇文章中的一段来记住这些单词. 文章由m个单词构成,她想在文章中找出连续的一段,其中包含最多的她想要 ...

  4. 「GXOI / GZOI2019」简要题解

    「GXOI / GZOI2019」简要题解 LOJ#3083. 「GXOI / GZOI2019」与或和 https://loj.ac/problem/3083 题意:求一个矩阵的所有子矩阵的与和 和 ...

  5. drill 数据库查询方式简单说明

    1. mysql   select * from mysql-storage.mysqldb.mysqltable   2. oracle    select * from oracle-storag ...

  6. ubuntu :安装skype聊天工具

    如题,今天就想搞个软件在ubuntu能聊天,查一下skype,好像网上有人说不是每个安装包都用的了,skype-ubuntu-precise_4.2.0.13-1_i386.deb可以, 我在微盘下载 ...

  7. Socket服务端

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  8. Hibernate学习3—映射对象标识符(OID)

    一.Hibernate 用对象标识符(OID)来区分对象 作如下代码的实验: public class StudentTest { public static void main(String[] a ...

  9. python接口自动化21-下载excel文件(Content-Type:octets/stream)

    前言 Content-Type类型为octets/stream,这种一般是文件类型了,比如有时候需要导出excel数据,下载excel这种场景如何用python来实现呢? 抓下载接口 1.下载的场景如 ...

  10. Timesten 日常管理命令合集

    Timesten 日常管理命令合集 以下所有操作都是基于TT  11 版,早前版本本人没用过,命令是否适用我不清楚啊! 各类服务管理 一.TT的启停  停服务:  1.停止复制与cache 进程:  ...