软测单独项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
4.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FangYar.WebUI.WebCommon
{
public class HttpModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
//context.BeginRequest += new EventHandler(Application_BeginRequest);
context.EndRequest += new EventHandler(Application_EndRequest);
}
void Application_EndRequest(Object source, EventArgs e)
{
//调用接口是否验证登录:0、不验证;其他、验证
var IsCheckLogin = System.Configuration.ConfigurationManager.AppSettings["IsCheckLogin"] + "";
if (!string.IsNullOrWhiteSpace(IsCheckLogin))
{
if (IsCheckLogin != "0")
{
//验证是否登录
HttpApplication app = (HttpApplication)source;
var req = app.Request;
//判断是否APP或者小程序访问
if (!Common.WebCommonUtil.IsPhoneRequest(app.Context))
{
//不是APP或小程序访问
//判断是否登录接口
// /ashx/LoginHandler.ashx
var firePath = app.Request.FilePath;
if (firePath.Contains("/ashx/"))
{
if (!firePath.Contains("/ashx/LoginHandler.ashx"))
{
//不是登录接口,验证是否存在cook信息
try
{
var cook = app.Context.Request.Cookies;
var cookInfo = cook["kn_root_cookie"];
if (cookInfo != null)
{
//判断是否存在登录缓存信息
if (string.IsNullOrWhiteSpace(cookInfo.Value))
{
//不存在登录缓存信息,返回数据
app.Context.Response.Write("{\"code\":-1,\"msg\":\"Not Login!\"}");
app.Context.Request.Abort();
}
}
else
{
//app.Context.Response.Clear();
//不存在登录缓存信息,返回数据
app.Context.Response.Write("{\"code\":-1,\"msg\":\"Not Login!\"}");
//app.Context.Response.End();
app.Context.Request.Abort();
//app.Context.Response.Close();
//return;
}
}
catch (Exception ex)
{
//不存在登录缓存信息,返回数据
//app.Context.Response.Write("{\"code\":-1,\"msg\":\"Not Login Login!\"}");
app.Context.Response.Write("{\"code\":-1,\"msg\":\"Not Login!\"}");
app.Context.Request.Abort();
}
}
}
}
}
}
}
// Define a custom PostAcquireRequestState event handler.
public void Application_BeginRequest(object o, EventArgs ea)
{
HttpApplication httpApp = (HttpApplication)o;
HttpContext ctx = HttpContext.Current;
ctx.Response.Write(" Executing PostAcquireRequestState ");
}
}
}