问题:

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. 解决在V2.0中子组件使用v-model接收来自父组件的值异常

    当我们使用父组件向子组件传值,当子组件中是v-model使用该值时会报:[Vue warn]: Avoid mutating a prop directly since the value will ...

  2. mybatis关系映射之一对多和多对一

    本实例使用用户(User)和博客(Post)的例子做说明: 一个用户可以有多个博客, 一个博客只对应一个用户 一. 例子(本实体采用maven构建): 1. 代码结构图: 2. 数据库: t_user ...

  3. php用户名密码

    http://112.124.47.59:8090/activity/index/free?mobile=15652701923&tcode=f9380859085200714&s=7 ...

  4. 关于 Thread.currentThread()

    currentThread()  到底是什么? 其实currentThread() 只是Thread 的一个静态方法.返回的正是执行当前代码指令的线程引用: /** * Returns a refer ...

  5. Flex4学习笔记 checkBox RadioButton DropDownList colorPicker

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  6. 【ASP.NET 进阶】仿百度文库文档在线预览(支持格式.pdf,.doc,docx,xls,xlsx,.ppt,pptx)

    在[ASP.NET]PDF文件在线预览(类似百度文库)基础上进行了office文件到pdf文件的转换,然后在显示出来,效果如下: 问题说明: 1.请通过以下方式添加 Office COM 组件. 2. ...

  7. charles抓包的安装,使用说明以及常见问题解决(windows)

    charles抓包的安装,使用说明以及常见问题解决(windows) https://blog.csdn.net/zhangxiang_1102/article/details/77855548

  8. delphi 第三方组件 log4cpp.dll

    log4cpp.dll LogHelper.dll TcxGridSite TcxSpreadSheetBook TcxSpreadSheetBook TcxTreeList TcxButtonEdi ...

  9. electron安装到第一个实例

    1.node.js下载,然后安装.下载地址:链接:http://pan.baidu.com/s/1o7TONhS 密码:fosa 2.cmd下输入:npm install electron-prebu ...

  10. day09-数据库插入中文报错

    在向数据库表中插入中文时一直报错 MySQL的默认编码是Latin1,不支持中文,要支持中文需要把数据库的默认编码修改为gbk或者utf8. 1.需要以root用户身份登陆才可以查看数据库编码方式(以 ...