using System;
using System.Collections.Generic;
using System.Web.SessionState;
using System.Text;
using System.IO;
using System.Web;
using MyLib;
namespace NDRcw
{
public class CDealLabel : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
application.AcquireRequestState += new EventHandler(application_AcquireRequestState);
}
void application_AcquireRequestState(object sender, EventArgs e) //检查用户是否登录、是否有权限
{
// 获取应用程序
HttpApplication Application = (HttpApplication)sender;
HttpRequest request = Application.Context.Request;
HttpResponse response = Application.Context.Response;
string sFile = request.PhysicalPath.Trim();
string sPath = request.Path.Trim();
if (CFunc.StrLeft(sPath, 1) == "/") sPath = CFunc.StrRight(sPath, sPath.Length - 1);
string[] sAryPath=sPath.Split(new char[] { '/' });
string sDirectory=sAryPath[0].ToLower().Trim();
if(sDirectory!="manage") return;
string sFileName = Path.GetFileName(sFile).ToLower();
if (sFileName == "index.aspx") return;
//检查用户是否已经登录
string sUserID=CFunc.ToString(Application.Context.Session["UserID"]);
if (sUserID.Trim() == "")
{
Application.Server.Transfer("/manage/index.aspx");
}
//检查用户权限
//TODO
CUserInfo server = new CUserInfo();
int iPower = server.CheckPower(sFileName, sUserID);
if (iPower == 0)
{
Application.Server.Transfer("/manage/error.htm");
}
}
private void Application_BeginRequest(Object source, EventArgs e) //处理前台标签
{
HttpApplication Application = (HttpApplication)source;
HttpRequest request = Application.Context.Request;
HttpResponse response = Application.Context.Response;
HttpServerUtility httpSvr = Application.Context.Server;
HttpSessionState mySession=Application.Context.Session;
string sFile = request.PhysicalPath.Trim();
string sPath = request.Path.Trim();
if (CFunc.StrLeft(sPath, 1) == "/") sPath = CFunc.StrRight(sPath, sPath.Length - 1);
string[] sAryPath=sPath.Split(new char[] { '/' });
string sDirectory=sAryPath[0].ToLower().Trim();
switch(sDirectory)
{
case "usersite":
if (Path.GetExtension(sFile).ToLower().Trim() != ".aspx") return;
StreamReader sr = new StreamReader(sFile);
string sHtml = sr.ReadToEnd();
sr.Close();
if (sHtml.IndexOf("{$") > 0)
{
System.Text.StringBuilder sb = new StringBuilder();
httpSvr.Execute(request.RawUrl, new System.IO.StringWriter(sb));
sHtml = sb.ToString();
CLabelInfo server = new CLabelInfo();
sHtml = server.DealTemplate(sHtml, request.QueryString);
response.Write(sHtml);
response.End();
}
break;
}
}
public void Dispose()
{
}
}
}
浙公网安备 33010602011771号