ASP.NET 登录验证 ihttpmoudle
问题:
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的更多相关文章
- C# asp.net 抓取需要登录的网页内容 抓取asp.net登录验证的网站
private void btnASPNET_Click(object sender, EventArgs e) { Dictionary<string, s ...
- asp.net登录验证FormsAuthenticationTicket和FormsAuthentication类
登录部分使用的类 FormsAuthentication 为 Web 应用程序管理 Forms 身份验证服务. 配置启用身份验证,WEB.config配置: <system.web> ...
- ASP.NET登录验证
protected void btnLogin_Click(object sender, EventArgs e) { string username = txtUserName.Value.Trim ...
- asp.net登录状态验证
文章:ASP.NET 登录验证 文章:ASP.NET MVC下判断用户登录和授权状态方法 文章:.net学习笔记---HttpHandle与HttpModule 第一篇文章,介绍了 1)早期的Base ...
- Asp.NetMVC利用LigerUI搭建一个简单的后台管理详解(函登录验证)
上一篇 Asp.Net 中Grid详解两种方法使用LigerUI加载数据库数据填充数据分页 了解了LigerUI 中Grid的基本用法 现在结合上一篇的内容做一个简单的后台管理,当然也有前台的页面 ...
- ASP.NET MVC5入门3之登录验证
参考: HTML页面模版: http://www.ui.cn/detail/70262.html(第38个) MVC后台代码参考: http://www.oschina.net/p/nfine 开发环 ...
- ASP.NET MVC 登录验证
好久没写随笔了,这段时间没 什么事情,领导 一直没安排任务,索性 一直在研究代码,说实在的,这个登录都 搞得我云里雾里的,所以这次我可能也讲得不是 特别清楚,但是 我尽力把我知道的讲出来,顺便也对自 ...
- ASP.NET MVC4 Forms 登录验证
Web.config配置: 在<system.web>节下: <authentication mode="Forms"> <forms loginUr ...
- ASP.NET MVC3 实现用户登录验证
自定义一个授权筛选器类,继承于AuthorizeAttribute: using System; using System.Web; using System.Web.Mvc; namespace M ...
随机推荐
- 关于dumper和mysqldump的
最近在做版本更新 使用dumper在连接阿里云的RDS的时候 老是提示 需要超级管理员权限 无能只能使用系统自带的mysqldump了 语句简单方便 而且导出的表 没有加载库信息 mysqldump ...
- winform 之控件ListView
使用ListView构建表格展示数据 1.添加列数据:控件ListView--上方按钮--视图(Details)--编辑列--添加 2.添加行数据:--编辑项(行)--添加 添加数据:Text:默认添 ...
- Duboo 与springboot整合
https://github.com/apache/incubator-dubbo-spring-boot-project 当采用properties方式时,可以用下方的注解 1.pom <de ...
- 最详细安装Esxi
https://www.vmware.com/cn/products/vsphere-hypervisor.html Exsi 是一款虚拟化系统,与VMware,VirtualBox不同,它不需要安装 ...
- sql中的函数
函数类别 作用 聚合函数 执行的操作是将多个值合并为一个值.例如 COUNT.SUM.MIN 和 MAX. 配置函数 是一种标量函数,可返回有关配置设置的信息. 转换函数 将值从一种数据类型转换为另一 ...
- Tornado的安装使用
https://blog.csdn.net/a312024054/article/details/52207367 tornado原理: tornado的使用 import tornado.ioloo ...
- jquery接触初级-----ajax 之:jquery_ajax 方法
1. $.get() 方法: 格式:$.get( url,[,data],[,callback],[,type] ); data: 采用键值对的方式存储于对象中; callback: 载入成功时(当 ...
- ELK实时日志分析平台环境部署--完整记录(转)
在日常运维工作中,对于系统和业务日志的处理尤为重要.今天,在这里分享一下自己部署的ELK(+Redis)-开源实时日志分析平台的记录过程(仅依据本人的实际操作为例说明,如有误述,敬请指出)~ ==== ...
- linux 协议栈tcp的rst报文中,seq的选取问题
之前在<深入理解并行编程>的群里,有个小米的兄弟问了一个问题,服务器A发包给服务器B,Seq是1,但是在未能收到服务器B的报文回复的情况下,发送了rst,但是rst报文中,对应的seq是1 ...
- 在系统中使用Bean Validation验证参数
转自:http://www.importnew.com/18561.html 为什么要使用Bean Validation? 当我们实现某个接口时,都需要对入参数进行校验.例如下面的代码 1 2 3 ...