zoukankan      html  css  js  c++  java
  • 我HttpModule测试

    代码
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Diagnostics;
    using System.Web.SessionState;

    /// <summary>
    /// MyHttpModule 的摘要说明
    /// </summary>
    public class MyHttpModule: IHttpModule
    {

    public void Init( HttpApplication httpApp)
    {
    httpApp.AuthenticateRequest
    += new EventHandler(httpApp_AuthenticateRequest);
    }

    void httpApp_AuthenticateRequest(object sender, EventArgs e)
    {
    //string name= HttpContext.Current.User.Identity.Name;
    //EventLog log = new EventLog();
    //log.Source = "asp.net应用程序";
    //log.WriteEntry(name + " 被授权");
    HttpApplication app = (HttpApplication)sender;

    HttpSessionState Session
    = app.Context.Session;
    HttpRequest Request
    = app.Context.Request;
    HttpResponse Response
    = app.Context.Response;

    string url = Request.RawUrl;
    if (url.IndexOf("SystemManager") != -1 && url.IndexOf("login.aspx") == -1 )
    {
    Response.Write(
    "未授权的访问");
    Response.End();
    }
    //app.Context.Response.Write(Request.RawUrl);
    //if (Session["NAME"] == null)
    //{
    // HttpContext.Current.Response.Write("未授权的访问");
    // HttpContext.Current.Response.End();
    //}
    }
    public void Dispose()
    { }
    }
    <system.web>
      <httpModules>
    <add name="MyLog" type="MyHttpModule" />
    </httpModules>
    </system.web>
  • 相关阅读:
    AWS Redshift 采坑记
    EF Core 小工具
    Setup .net core EF
    Bat 使用MSBuild 制作发布包 (更新20180713)
    Https web Api 拉取数据踩坑记录
    C# 后台程序 通过批处理进行监控
    C#计算日期步进
    IIS 预热 (8.0及8.0以上版本)
    MSBuild 执行文档,关于使用命令行编译
    基于Bamboo的CI配置汇总(.Net Web及Api)
  • 原文地址:https://www.cnblogs.com/wucg/p/1722195.html
Copyright © 2011-2022 走看看