httpModule控制url跳转

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

ContractedBlock.gif ExpandedBlockStart.gif 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()
        {

        }

    }
}

转载于:https://www.cnblogs.com/mynote/archive/2009/08/03/1537382.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值