问题:

1.iis版本不同(IIS7.0,应用程序池采用的是集成模式,换成经典模式才起作用.)

在 IIS 7 以下的版本中,应用以下配置:

<system.web>
<httpModules>
<add name="Cftea.MyHttpModule" type="CfteaHttpModule程序集" />
</httpModules>
</system.web>

在 IIS 7 及以上的版本中,应用以下配置

<system.webServer>
<modules>
<add name="Cftea.MyHttpModule" type="CfteaHttpModule程序集" />
</modules>
</system.webServer>

<add name="命名空间.名字" type="程序集名字" />

例如:

<add name="web.common.MyModule" type="web" />

2.具体实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace login.common
{
public class MyMoudle : IHttpModule
{
public void Dispose()
{
throw new NotImplementedException();
} public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
} private void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication ha = (HttpApplication)sender;
int length = ha.Context.Request.Url.Segments.Length;
string a = ha.Context.Request.RawUrl;
string path = ha.Context.Request.Url.Segments[length - ].ToString(); //获得访问的页面
bool IsLogingPage = path.ToLower().Equals("login.aspx"); //比较是否是Login.aspx 是就不进入
if (!IsLogingPage)
{
//var CookiesDemo = ha.Context.Request.Cookies["UserID"];
var CookiesDemo = ha.Session["UserID"];
if (CookiesDemo == null ||CookiesDemo.Equals(""))
{ //ha.Context.Response.Redirect("/Login.aspx");
ha.Context.Response.Write("<script>alert('login failed!');url='/login.aspx?url="+ a + "';if(window.parent!=null){window.parent.location=url;}else{this.location=url;};</script>");
ha.Context.Response.End();
}
}else
{
}
}
}
}

ASP.NET 登录验证 ihttpmoudle的更多相关文章

  1. C# asp.net 抓取需要登录的网页内容 抓取asp.net登录验证的网站

    private void btnASPNET_Click(object sender, EventArgs e)        {            Dictionary<string, s ...

  2. asp.net登录验证FormsAuthenticationTicket和FormsAuthentication类

    登录部分使用的类 FormsAuthentication   为 Web 应用程序管理 Forms 身份验证服务. 配置启用身份验证,WEB.config配置: <system.web> ...

  3. ASP.NET登录验证

    protected void btnLogin_Click(object sender, EventArgs e) { string username = txtUserName.Value.Trim ...

  4. asp.net登录状态验证

    文章:ASP.NET 登录验证 文章:ASP.NET MVC下判断用户登录和授权状态方法 文章:.net学习笔记---HttpHandle与HttpModule 第一篇文章,介绍了 1)早期的Base ...

  5. Asp.NetMVC利用LigerUI搭建一个简单的后台管理详解(函登录验证)

    上一篇 Asp.Net 中Grid详解两种方法使用LigerUI加载数据库数据填充数据分页  了解了LigerUI 中Grid的基本用法  现在结合上一篇的内容做一个简单的后台管理,当然也有前台的页面 ...

  6. ASP.NET MVC5入门3之登录验证

    参考: HTML页面模版: http://www.ui.cn/detail/70262.html(第38个) MVC后台代码参考: http://www.oschina.net/p/nfine 开发环 ...

  7. ASP.NET MVC 登录验证

     好久没写随笔了,这段时间没 什么事情,领导 一直没安排任务,索性 一直在研究代码,说实在的,这个登录都 搞得我云里雾里的,所以这次我可能也讲得不是 特别清楚,但是 我尽力把我知道的讲出来,顺便也对自 ...

  8. ASP.NET MVC4 Forms 登录验证

    Web.config配置: 在<system.web>节下: <authentication mode="Forms"> <forms loginUr ...

  9. ASP.NET MVC3 实现用户登录验证

    自定义一个授权筛选器类,继承于AuthorizeAttribute: using System; using System.Web; using System.Web.Mvc; namespace M ...

随机推荐

  1. python中的jion

    on将列表或元组中的每个元素连接起来,举个例子: 1 a = ["hello", "world", "dlrb"] 2 a1 = " ...

  2. foreachPartition来写数据库

    foreachPartition,在生产环境中,通常来说,都使用foreachPartition来写数据库的 使用批处理操作(一条SQL和多组参数) 发送一条SQL语句,发送一次 一下子就批量插入10 ...

  3. Ubuntu系统安装

    一:Ubuntu14.04 安装及使用:[1]制作安装U盘(选择USB-HDD+”并单击后,           一定要点“写入”,注意,“写入”是一个按钮) 以下是详细的连接步骤: https:// ...

  4. redistemplate优雅地操作redis redis 工具类

    参考:https://www.cnblogs.com/superfj/p/9232482.html redis 工具类 package com.service; import org.springfr ...

  5. leetcode987

    public class Solution { private Dictionary<int, List<KeyValuePair<int,int>>> dic = ...

  6. nosql数据库:mongodb,redis,memcached,其优缺点和使用应用场景

    1.mongodb (1)是文档型的非关系型数据库,使用bson结构.其优势在于查询功能比较强大,能存储海量数据,缺点是比较消耗内存. (2)一般可以用来存放评论等半结构化数据,支持二级索引. 适合存 ...

  7. jsfl 常用方法

    //打开fla文档 fl.openDocument (JSFL_PATH+"tongzhi.fla"); //发布flash fl.getDocumentDOM().publish ...

  8. [ SHELL编程 ] 自动删除操作系统用户

    Linux中经常需要删除用户,通常手工操作执行userdel操作即可,如果删除失败出现错误提示按照提示错误进行操作即可.如果是脚本需要调用删除用户操作呢?利用如下实例中drop_user删除用户函数, ...

  9. openwrt手工配置pptpd

    官方wiki:http://wiki.openwrt.org/doc/howto/vpn.server.pptpd#prerequisites 20190220更新:PPTP VPN协议已经被 IOS ...

  10. iframe多窗口

    Window 对象 浏览器会在其打开一个 HTML 文档时创建一个对应的 window 对象.但是,如果一个文档定义了一个或多个框架(即,包含一个或多个 frame 或 iframe 标签),浏览器就 ...