httpModule控制url跳转
httpModule控制url权限的使用方法代码如下:

Code
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using CNNet.CommonBLL;
/// <summary>
/// BasePage 的摘要说明
/// Create:wangxiaoming
/// Descri:网站权限控制模块
/// </summary>
namespace MyModule
{
public class DEPHttpModule : System.Web.IHttpModule
{
public void Init(HttpApplication application)
{
application.AcquireRequestState += (new
EventHandler(this.Application_AcquireRequestState));
}
public DEPHttpModule()
{
}
private void Application_AcquireRequestState(Object source, EventArgs e)
{
HttpApplication Application = (HttpApplication)source;
string url = Application.Context.Request.Path;
String AppPath = Application.Context.Request.ApplicationPath;
#region 企业
if (url.IndexOf("company/pages/") > 0)
{
CNNet.CommonBLL.Cookie cookie = new CNNet.CommonBLL.Cookie();
string userCode = cookie.getCookie("cnnetcompanyname");
string companycode = cookie.getCookie("cnnetcompanycode");
if (string.IsNullOrEmpty(userCode) || string.IsNullOrEmpty(companycode))
{
Application.Context.Server.Transfer(AppPath + "/company/Login.aspx");
}
else
{
string isExistPage = CNNet.CommonBLL.EnumBind.GetEnumUrlByURL(url, typeof(CNNet.CommonBLL.Dictionary.DEP_Control_Infor));
if (isExistPage != "101" && string.IsNullOrEmpty(isExistPage))
{
Application.Context.Server.Transfer(AppPath + "/company/message/HttpMessage.aspx");
}
else if (isExistPage == "101")
{
}
else
{
if (CNNet.CommonDAL.DbHelperSQL.GetSingle(string.Format(CNNet.CommonBLL.Constants.sql_EP_PowerLinkTo_One, companycode, "UserName='" + userCode + "'", "PowerCode='" + isExistPage + "'")) == null)
{
Application.Context.Server.Transfer(AppPath + "/company/message/HttpQX.aspx");
}
}
}
}
#endregion
#region 分站
if ((url.ToUpper().IndexOf("CENT") > 0 && url.ToUpper().IndexOf(".ASPX") > 0) || url.ToUpper().IndexOf("Search/pages/sub_index.aspx".ToUpper()) > 0 || url.ToUpper().IndexOf("search/pages/sub_indexDe.aspx".ToUpper()) > 0)
{
string Domain = "";
CNNet.BLL.RejoiceGarden gardenbll = new CNNet.BLL.RejoiceGarden();
Domain = Application.Context.Request.Url.Authority;
string secodedomain = String.Empty;
secodedomain = Domain.Split('.')[0].ToString();
CNNet.CommonBLL.Cookie cookie = new CNNet.CommonBLL.Cookie();
string gardencodevalue = "";
gardencodevalue = CNNet.CommonBLL.ConfigHelper.GetGardenCode();
cookie.delCookie(gardencodevalue);
string gardencode = String.Empty;
try
{
gardencode = gardenbll.GetGardenCodeByDomain(secodedomain);
}
catch
{
gardencode = "0";
}
if (gardencode == "")
{
gardencode = "0";
}
//本地测试用北京园区编码
if (gardencode == "0")
gardencode = "11010001";
SetCookie(gardencode);
}
#endregion
}
private void SetCookie(string gardencode)
{
//System.Web.HttpCookie cookie = new System.Web.HttpCookie("gxrcgardencode");
//DateTime dt = DateTime.Now;
//cookie.Expires = dt.AddMinutes(0);
//cookie.Value = gardencode;
//System.Web.HttpContext.Current.Response.AppendCookie(cookie);
System.Web.HttpContext.Current.Response.Cookies[ConfigHelper.GetGardenCode()].Value = gardencode;
}
public void Dispose()
{
}
}
}


using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using CNNet.CommonBLL;
/// <summary>
/// BasePage 的摘要说明
/// Create:wangxiaoming
/// Descri:网站权限控制模块
/// </summary>
namespace MyModule
{
public class DEPHttpModule : System.Web.IHttpModule
{
public void Init(HttpApplication application)
{
application.AcquireRequestState += (new
EventHandler(this.Application_AcquireRequestState));
}
public DEPHttpModule()
{
}
private void Application_AcquireRequestState(Object source, EventArgs e)
{
HttpApplication Application = (HttpApplication)source;
string url = Application.Context.Request.Path;
String AppPath = Application.Context.Request.ApplicationPath;
#region 企业
if (url.IndexOf("company/pages/") > 0)
{
CNNet.CommonBLL.Cookie cookie = new CNNet.CommonBLL.Cookie();
string userCode = cookie.getCookie("cnnetcompanyname");
string companycode = cookie.getCookie("cnnetcompanycode");
if (string.IsNullOrEmpty(userCode) || string.IsNullOrEmpty(companycode))
{
Application.Context.Server.Transfer(AppPath + "/company/Login.aspx");
}
else
{
string isExistPage = CNNet.CommonBLL.EnumBind.GetEnumUrlByURL(url, typeof(CNNet.CommonBLL.Dictionary.DEP_Control_Infor));
if (isExistPage != "101" && string.IsNullOrEmpty(isExistPage))
{
Application.Context.Server.Transfer(AppPath + "/company/message/HttpMessage.aspx");
}
else if (isExistPage == "101")
{
}
else
{
if (CNNet.CommonDAL.DbHelperSQL.GetSingle(string.Format(CNNet.CommonBLL.Constants.sql_EP_PowerLinkTo_One, companycode, "UserName='" + userCode + "'", "PowerCode='" + isExistPage + "'")) == null)
{
Application.Context.Server.Transfer(AppPath + "/company/message/HttpQX.aspx");
}
}
}
}
#endregion
#region 分站
if ((url.ToUpper().IndexOf("CENT") > 0 && url.ToUpper().IndexOf(".ASPX") > 0) || url.ToUpper().IndexOf("Search/pages/sub_index.aspx".ToUpper()) > 0 || url.ToUpper().IndexOf("search/pages/sub_indexDe.aspx".ToUpper()) > 0)
{
string Domain = "";
CNNet.BLL.RejoiceGarden gardenbll = new CNNet.BLL.RejoiceGarden();
Domain = Application.Context.Request.Url.Authority;
string secodedomain = String.Empty;
secodedomain = Domain.Split('.')[0].ToString();
CNNet.CommonBLL.Cookie cookie = new CNNet.CommonBLL.Cookie();
string gardencodevalue = "";
gardencodevalue = CNNet.CommonBLL.ConfigHelper.GetGardenCode();
cookie.delCookie(gardencodevalue);
string gardencode = String.Empty;
try
{
gardencode = gardenbll.GetGardenCodeByDomain(secodedomain);
}
catch
{
gardencode = "0";
}
if (gardencode == "")
{
gardencode = "0";
}
//本地测试用北京园区编码
if (gardencode == "0")
gardencode = "11010001";
SetCookie(gardencode);
}
#endregion
}
private void SetCookie(string gardencode)
{
//System.Web.HttpCookie cookie = new System.Web.HttpCookie("gxrcgardencode");
//DateTime dt = DateTime.Now;
//cookie.Expires = dt.AddMinutes(0);
//cookie.Value = gardencode;
//System.Web.HttpContext.Current.Response.AppendCookie(cookie);
System.Web.HttpContext.Current.Response.Cookies[ConfigHelper.GetGardenCode()].Value = gardencode;
}
public void Dispose()
{
}
}
}