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 ...
随机推荐
- Link Shell Extension
Link Shell Extension http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html
- web service 部 分
1 .WEB SERVICE 名 词 解 释 .JSWDL 开 发 包 的 介 绍 .JAXP .JAXM 的 解 释 . SOAP .UDDI,WSDL 解 释 . Web ServiceWeb S ...
- Dubbo的学习
Dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring框架无缝集成. Dubbo是一款高性能.轻量级的开源Java RP ...
- leetcode991
class Solution: def brokenCalc(self, X: 'int', Y: 'int') -> 'int': if X>=Y : return Y-X else: ...
- EmEditor
姓 名:ttrar.com 序 列 号:DKAZQ-R9TYP-5SM2A-9Z8KD-3E2RK 免费版地址:https://zh-cn.emeditor.com/#download
- Crontab 删除N天前日志
linux是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种爽快的事情.不用你去每天惦记着是否需要清理日志 ...
- NativeClient开发指南
https://blog.csdn.net/column/details/24458.html
- SRM-相关资料路径
SRM采购管理平台功能介绍 https://wenku.baidu.com/view/b05cff5930b765ce0508763231126edb6f1a763c.html https://wen ...
- groovy语法
1.注释1.1. 单行注释1.2. 多行注释1.3. GroovyDoc注释1.4. Shebang线2.关键词3.标识符3.1. 普通标识符3.2. 带引号的标识符4.字符串4.1. 单引号字符串4 ...
- hadoop搭建部署
HDFS(Hadoop Distributed File System)和Mapreduce是hadoop的两大核心: HDFS(文件系统)实现分布式存储的底层支持 Mapreduce(编程模型)实现 ...