页面重定向

简单介绍一下<httphander><httpModule>

 

httphander 重定向URL

WebConfig中的配置

  <httpHandlers>

       <add verb="GET" path="bb.karen" type="BLL.HanderTest,BLL"/>

</httpHandlers>

其中BLL.HanderTest为类,BLL为所属DLL

 

 实现IHttpHandler接口的类

using System;

using System.Collections.Generic;

using System.Text;

using System.Web;

 

namespace BLL

{

    class HanderTest : IHttpHandler

    {

        public HanderTest()

        {

 

        }

        public void ProcessRequest(System.Web.HttpContext context)

        {

            System.Web.HttpResponse obj = context.Response;

            obj.Write("<html><body><h1>this is a httphandler test!");

            obj.Write("</body></html>");

        }

 

        public bool IsReusable

        {

            get

            {

                return true;

            }

        }

 

    }

}

 

当在页面中输入http://../bb.karen 时将显示 this is a httphandler test!,以此达到重定向的目的。

 

 

httpModule 实现权限验证

WebConfig配置

<configuration>
    <system.web>
        <httpModules>
            <add name=" MyModule " type=" MyModule, MyModule" /> 
        </httpModules>
    </system.web>

</configuration>

 

类中实现

using System;

using System.Web;

namespace MyModule

{

          public class MyModule : IHttpModule

          {

                    public void Init(HttpApplication application)

                    {

                              application. AcquireRequestState += (new

                    EventHandler(this.Application_AcquireRequestState));

                    }

          private void Application_AcquireRequestState (Object source, EventArgs e)

                    {

                               HttpApplication Application = (HttpApplication)source;

                               User user=Application.Context.Sesseion["User"]  //获取User

                               string url=Application.Context.Request.Path;

//获取客户访问的页面

                               Module module= //根据url得到所在的模块

                               If(!RightChecker.HasRight(user,module))

                               Application.Context.Server.Transfer("ErrorPage.aspx");

                               //如果没有权限,引导到错误处理的页面

                    }

                    public void Dispose()

                    {

                    }

          }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值