Global中添加AcquireRequestState事件。

protected void Application_AcquireRequestState(object sender, EventArgs e)
{
Uri url = Request.Url; //得到当前请求的URL
//访问Admin目录,需要进行登陆验证。
if (url.AbsolutePath.ToLower().StartsWith("/admin"))
{
//如果Login.aspx写在admin目录下,需要排除对Login.aspx验证。 if (HttpContext.Current.Session["Name"] == null)
{
HttpContext.Current.Response.Redirect("~/Login.aspx");
}
}
}

也可以使用IHttpModule接口,创建一个类,在配置文件中调用下。

//不要忘记:在配置文件中配置一下。
//<httpModules>
//    <add name="CheckAdminModule" type="Web.Common.CheckAdminModule"/>
//</httpModules>

public class CheckAdminModule:IHttpModule
{
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(OnAcquireRequestState);
} public void OnAcquireRequestState(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
Uri url = application.Request.Url; //得到当前请求的URL
//访问Admin目录,需要进行登陆验证。
if (url.AbsolutePath.ToLower().StartsWith("/admin"))
{
//如果Login.aspx写在admin目录下,需要排除对Login.aspx验证。
if (application.Session["Name"] == null) //HttpContext.Current.Session["Name"]
{
application.Response.Redirect("~/Login.aspx");
}
}
}
}

asp.net 在AcquireRequestState事件中判断登陆验证。的更多相关文章

  1. BCB key事件中判断Shift、Alt、Ctrl状态

    BCB key事件中判断Shift.Alt.Ctrl状态: 类似此事件中 void __fastcall TForm1::keydown(TObject *Sender, WORD &Key, ...

  2. ASP.NET Global Application_Error事件中访问Session报错 解决

    报错信息:会话状态在此上下文中不可用 protected void Application_Error(object sender, EventArgs e) { //以此判断是否可用Session ...

  3. 在cc.EventListener.TOUCH_ONE_BY_ONE事件中判断拖动物离哪边近飞向那边

    需将拖动物坐标和要飞向物坐标转化为整个layer的坐标,因为人们判断远近是根据整个layer来看的.

  4. ASP.NET服务器控件OnClientClick事件中Eval()作为js方法的参数的一种写法

    参考代码: <input type="button" OnClientClick='<%#Eval("DeptID", "DelUserD ...

  5. .NET winform 的keypress事件中判断当用户按下的是哪个键

    keys是按键的枚举类型 private void txtPropertyValue_KeyPress(object sender, KeyPressEventArgs e) { if ((Keys) ...

  6. ASP.NET MVC 4.0中选择Windows 验证默认出错拒绝访问的原因和解决方案

    在VS 2012或者2013 中,根据模板创建一个ASP.NET MVC 4.0的应用程序,选择下面的模板 然后选择Intranet Application 不对源代码做任何修改,直接按下F5调试,会 ...

  7. 【转】C#中判断扫描枪输入与键盘输入

    提出问题:在收货系统中,常常要用到扫描枪扫描条码输入到TextBox,当条码无法扫描时,需要手工输入.如果是扫描枪输入时,我们将自动去判读条码,而手工输入时,最终需要加按回车键确认后判读条码.这时候我 ...

  8. WinForm中TextBox 中判断扫描枪输入与键盘输入

    本文转载:http://www.cnblogs.com/Hdsome/archive/2011/10/28/2227712.html 提出问题:在收货系统中,常常要用到扫描枪扫描条码输入到TextBo ...

  9. Java的登陆验证问题

    java中的登陆验证问题可以有多种方式进行验证,通过拦截器功能完成,可以通过过滤器功能完成,也可以简单的代码在JSP页面中单独完成,其中都 涉及到一个关键的验证步骤,这个验证原理ASP,PHP,JAV ...

随机推荐

  1. Java获取系统安装软件列表

    /** * @author <a href="mailto:foohsinglong@gmail.com">kevin.long</a> * @descri ...

  2. typescript 接口的新认识

    interface 用于接收服务器的数据. eg: interface mmmmm { x: string, y: number, z: number, select: KnockoutObserva ...

  3. 第二百节,jQuery EasyUI,Tabs(选项卡)组件

    jQuery EasyUI,Tabs(选项卡)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 5.选项卡面板 本节课重点了解 EasyUI 中 Tabs(选项卡)组件的使用方 ...

  4. Redis特性和应用场景

    Redis特性 速度快 Redis使用标准C编写实现,而且将所有数据加载到内存中,所以速度非常快.官方提供的数据表明,在一个普通的Linux机器上,Redis读写速度分别达到81000/s和11000 ...

  5. day21 os random 序列json

    一.random模块     import random # print(random.random()) #0到1之间数 # print(random.uniform(10,20)) #范围内小数 ...

  6. Golang数组的四种声明方法

    //第一种 //var <数组名称> [<数组长度>]<数组元素> var arr [2]int arr[0]=1 arr[1]=2 //第二种 //var < ...

  7. yii rule

    https://blog.csdn.net/ljfrocky/article/details/46373691 http://www.yiichina.com/tutorial/997 http:// ...

  8. easyui datagrid加载数据的两种方式

    1.加载本地数据 var obj = {"total":2,"rows":[{id:"1",name:"一"},{id: ...

  9. 关于new HashMap<>(1)中1的理解(hashMap的加载因子)

    新入公司,阅读代码的时候发现了一行代码,为 Map<String, String> map=new HashMap<>(1); 对于这个括号里面的1不能理解,于是查了资料,大概 ...

  10. 【BZOJ3944/4805】Sum/欧拉函数求和 杜教筛

    [BZOJ3944]Sum Description Input 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 Output 一共T行,每行两个用 ...