![C#防盗链处理类的代码 C#防盗链处理类的代码](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
如下的内容是关于C#防盗链处理类的内容。
public class FileHandler:IHttpHandler
{
public FileHandler()
{
}
public void ProcessRequest(HttpContext context)
{
if ((context.Request.UrlReferrer == null) || (context.Request.UrlReferrer.Host == "localhost" && context.Request.UrlReferrer.Port == 16490))
{
context.Response.Expires = 0;
context.Response.Clear();
context.Response.ContentType = "rar";
context.Response.WriteFile(context.Request.PhysicalPath);
context.Response.End();
}
{
HttpResponse response = context.Response;
response.Redirect(context.Request.ApplicationPath + "/ErrorPage.htm");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}