asp.net运行时模块

局部水印效果

配置:(不需要)

创建:

HttpHandler程序(一般处理程序)

using System.Drawing;

usingSystem.Drawing.Imaging;

using System.IO;

关键代码:

public void ProcessRequest(HttpContextcontext)

{

            context.Response.ContentType = "text/plain";

            stringid = context.Request["id"].ToString();

            Imageimage;

            if(id == "8996733")

            {

                image = Image.FromFile(context.Server.MapPath("~/Image/8996733.jpg"));

                ImagewaterMark =Image.FromFile(context.Server.MapPath("~/Image/WaterMark.jpg"));

                Graphicsg =Graphics.FromImage(image);

                g.DrawImage(waterMark, newRectangle(new Point(10, 10),new Size(50,20)));

                g.Dispose();

                waterMark.Dispose();

            }

            else

            {

                image = Image.FromFile(context.Server.MapPath("~/Image/default.jpg"));

            }

            context.Response.ContentType = "image/jpeg";

           image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            image.Dispose();

            context.Response.End();

}

 

 

全局水印效果

配置:

  <httpHandlers>

        <addverb="*"path="Images/*.jpg"type="WebApplication1.CoverImage"/>

  </httpHandlers>

 

类:Handler:   CoverImage.cs

关键代码:

using System.Drawing;

usingSystem.Drawing.Imaging;

using System.IO;

 

        public void ProcessRequest(HttpContextcontext)

        {

            Imageimage;

            if(File.Exists(path))

            {

                image = Image.FromFile(path);

                ImagewaterMark =Image.FromFile(context.Server.MapPath("~/Images/WaterMark.jpg"));

                GraphicsG =Graphics.FromImage(image);

                G.DrawImage(waterMark, newRectangle(new Point(10, 10),new Size(50,20)));

                G.Dispose();

                waterMark.Dispose();

            }

            else

            {

                image = Image.FromFile(context.Server.MapPath("~/Images/default.jpg"));

            }

            context.Response.ContentType = "image/jpeg";

           image.Save(context.Response.OutputStream, ImageFormat.Jpeg);

        }

 

主窗体:代码

   <asp:ImageID="Image1" runat="server"Height="227px"

        ImageUrl="~/Images/8996733.jpg"Width="174px"/>

    <asp:ImageID="Image2" runat="server" Height="226px"

        ImageUrl="~/Images/9011122.jpg"Width="174px"/>

 

 

实现网页图片防盗链

关键代码:

  if (context.Request.UrlReferrer.Host== context.Request.Url.Host && context.Request.UrlReferrer.Port ==context.Request.Url.Port)

            {

                   context.Response.ContentType=”image/jpg”;

                   content.Response.WriteFile(content.Request.PhysicalPath);     //输出正确图片

            }

            else

            {

                  context.Response.ContentType=”image/jpg”;                   content.Response.WriteFile(content.Request.PhysicalApplicationPath+”res/163error.jpg”);     //输出错误图片

            }

简述从客户端发出请求后,IIS、模块、处理程序各自的工作过程。

IIS

Aspnet_isapi.dll

HttpApplication:通过一个实例处理收到众多请求,它的成员里面存储了针对每个请求的数据。

HttpMdoule:必经之路。在HTTP请求传递到真正的请求处理中心(HttpHandler)之前附加一些需要的信息在Http上,或者截获某些HTTP请求信息做一些额外的工作。

HttpHandler:是HTTP请求处理中心。

 

 

IIS是什么?

Internet Information Service 网络信息服务

 

Isapi是什么?

Internet Server Application Programming Interface ,网络服务应用程序接口

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值