C#防盗链处理类的代码

时间:2023-03-09 00:31:50
C#防盗链处理类的代码

如下的内容是关于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;
}
}
}