问题:

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. 54.纯 CSS 创作一副国际象棋

    原文地址:https://segmentfault.com/a/1190000015310484 感想:棋盘是 CSS 画的,棋子是 unicode 字符. HTML code: <html&g ...

  2. mysqld服务启动失败, Failed to restart mysqld.service: Unit not found.

    -bash-4.2# service mysqld restart Redirecting to /bin/systemctl restart mysqld.serviceFailed to rest ...

  3. CSS样式学习-2

    一.大小 ①width宽:height高. !注释:<a><span>无法使用该方法调整大小 控制元素的大小:宽高.下例是宽高分别100像素的div标签. <div st ...

  4. Java快速开发平台,JEECG 3.7.7闪电版本发布,增加多套主流UI代码生成器模板

    JEECG 3.7.7 闪电版本发布,提供5套主流UI代码生成器模板 导读 ⊙平台性能优化,速度闪电般提升           ⊙提供5套新的主流UI代码生成器模板(Bootstrap表单+Boots ...

  5. 用ADO操作数据库的方法步骤(ZT)

    http://www.cppblog.com/changshoumeng/articles/113437.html 学习ADO时总结的一些经验 用ADO操作数据库的方法步骤 ADO接口简介 ADO库包 ...

  6. python学习笔记之函数的参数

    函数的参数有位置参数和关键字参数,位置参数一定要在关键字参数的前面,位置参数的优先级是高于关键字参数的,否则会报错 def my_abs(a,b): print(a) print(b) my_abs( ...

  7. java script删除数组的方法集合(转载)

    一.清空数组 var ary = [1,2,3,4]; ary.splice(0,ary.length);//清空数组 console.log(ary); // 输出 [],空数组,即被清空了 二.删 ...

  8. 【389】Implement N-grams using NLTK

    Ref: Natural Language Toolkit Ref: n-grams in python, four, five, six grams? Ref: "Elegant n-gr ...

  9. 关于openwrt使用web升级提示固件版本不对的处理方法

    参考资料:https://blog.csdn.net/caoshunxin01/article/details/79355602 当openwrt使用web升级提示固件版本不对: The upload ...

  10. 今天折腾phantomjs+selenium的笔记

    1.debian8里安装phantomjs的方法: 参照:http://www.cnblogs.com/lgh344902118/p/6369054.html a.去https://bitbucket ...