.net进阶之 ----------- httphandler

本文详细介绍了ASP.NET中HTTP处理器的工作原理及其实现方式,包括处理特定文件类型的机制,并对比了HTTP处理器与HTTP模块之间的区别。通过示例代码展示了如何自定义HTTP处理器来处理特定请求。

 

网站访问的流程机制是怎么样的?

*.aspx

*.html

*.jpg

*.abcdefg

 

这些特殊后缀的文件 在 asp.net 里是如何处理的?

 

那就是HTTP处理器,也称 HTTP 处理程序

httphandler 和 httpModule 的区别:

   处理顺序

   处理对象

httphandler的代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Web.SessionState;


/// <summary>
/// HA 的摘要说明
/// </summary>

public class HA : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {

        context.Response.ContentType = "text/html";
       
        if  (context.Session["user"] == null)
        {

            string[] login = System.Configuration.ConfigurationManager.AppSettings.GetValues("url");
            context.Response.Redirect(login[0]);
            return;

        }

        context.Response.WriteFile(context.Request.FilePath);


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值