httpmodule
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
namespace ClassLibrary1
{
public class complete:IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication ha = (HttpApplication)sender;
XmlDocument doc = new XmlDocument();
doc.Load(ha.Context.Server.MapPath("~/ip.xml"));
XmlNode root = doc.SelectSingleNode("admin");
foreach (XmlNode xn in root.ChildNodes)
{
string ip=xn.InnerText;
//if (ip=="127.0.0.1")
//{
// ha.CompleteRequest();
// ha.Response.Write("你被限制登录");
//}
}
ha.Response.Write(ha.Request.UserHostAddress);
ha.Response.Write(GetClientIP());
string path = ha.Context.Request.Url.ToString();
// ha.Context.Response.Write(path.IndexOf("admin"));
int num = path.LastIndexOf("/")-1;
// path = path.Replace(".html",".aspx");
// ha.Server.Transfer("2.aspx");
if (path.IndexOf("admin") > 0)
{
if (ha.Context.Session["name"] == null) //是否Session中有用户名,若是空的话,转向登录页。
{
// ha.Context.Response.Write("<script>alert('请登录');</script>");
ha.Context.Response.Write("<script>top.location.href='login.aspx';</script>");
}
else
{
ha.Context.Response.Write("<script>alert('登录成功!');</script>");
}
}
else
{
}
}
// ip
private static string GetClientIP()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通