EF水印+验证码

·先创建ASP.NET项目,命名、添加MyHander.cs、Moduler.cs、添加img。

创建.png

·在Moduler.cs中编写相关代码[继承IHttpModule与IRequiresSessionState接口]

public class Moduler : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += BRQ;
context.EndRequest += ERQ;
}
private void ERQ(object sender, EventArgs e)
{
HttpApplication ht = sender as HttpApplication;
string url = ht.Request.Url.ToString();
if (url.LastIndexOf(".jpg") == -1)
{
ht.Response.Write("多少有点害怕");
}
}
private void BRQ(object sender, EventArgs e)
{
HttpApplication ht = sender as HttpApplication;
string url = ht.Request.Url.ToString();
if (url.LastIndexOf(".jpg") == -1)
{
ht.Response.Write("多少有点害怕");
}
}
}


添加Web窗体
·在Web.config中写入

<system.webServer>
<modules>
<add name="m1" type="WebApplication4.Moduler"/>
</modules>
<handlers>
<add verb="" name="h1" type="WebApplication4.MyHandler" path="images/.jpg" />
</handlers>
</system.webServer>


·在Moduler.cs中编写

public class MyHandler : IHttpHandler
{
public bool IsReusable => false;
public void ProcessRequest(HttpContext context)
{
string filename = context.Request.PhysicalPath;
Bitmap bitmap = new Bitmap(filename);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawString("ABCD", new Font("微软雅黑", 18, FontStyle.Bold), Brushes.LightPink, new Point(10, 5));
graphics.Flush();
bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}


·最后在web窗体中写入Img路径及图片大小。
本次文档编写结束!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 闲来无事,最近自己发现自己的验证码功能还没有写过。于是就写下了这篇文章。 界面就比较丑了,一个picturebox...
    黑哥聊dotNet阅读 11,965评论 0 0
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,806评论 1 32
  • 一、前言 有些时候开发者需要验证服务托管自己的服务器(开发者服务器拥有校验验证码的功能),然后可以更好处理自己的业...
    皮皮酱ye阅读 4,489评论 0 1
  • 答案,正式使用前请祛除答案以及选项的红色颜色! 1:C2:C3:D4:D5:B 6:B7:D8:B9:A10:D ...
    程序媛_阅读 3,335评论 0 0
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,732评论 28 53