zoukankan      html  css  js  c++  java
  • Create a httpmodule and session authentification

    1. Add following into web.config.

      <system.web>
        <httpModules>
          <add name="CustomAuthorizationModule" type="TstHttpModule.CustomAuthorizationModule" />
        </httpModules>

    2. Create a class into appdata folder

    2.1 Session is not null for the first time.

    2.2 OnAcquireRequestState event will be fired for more than one time. Requested css and icon files will also call this event, however, the session is null at that time. Specific requested page can be saw with following statement.

    string path = context.Request.Url.AbsolutePath;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace TstHttpModule
    {
        public class CustomAuthorizationModule : IHttpModule
        {
            public void Init(HttpApplication context){
                context.AcquireRequestState += OnAcquireRequestState;
            }
    
            public void Dispose(){
            }
    
            private void OnAcquireRequestState(object sender, EventArgs e){
                var context = ((HttpApplication)sender).Context;
                string path = context.Request.Url.AbsolutePath;
                if (context.Session == null){
    
                }
                else{
                    if (context.Session["UserID"] == null){
                        context.Session["UserID"] = "abc";
                    }
                    else {
                        var t = context.Session["UserID"];
                    }
                }
            }
        }
    }
  • 相关阅读:
    halcon三种模板匹配方法
    线阵相机与面阵相机的区别
    完整性检测
    halcon读取一张照片,并转化为灰度图像
    halcon车牌的识别
    HALCON学习之条形码实时扫描
    开关引脚测量
    ip sensor芯片级解决方案
    ip camera芯片级解决方案
    Parallel For Bug in static constructor
  • 原文地址:https://www.cnblogs.com/webglcn/p/2703792.html
Copyright © 2011-2022 走看看