您好,欢迎访问一九零五行业门户网

c# 防盗链接

1、建一个类 : handler.cs 内容如下: 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;
1、建一个类 : handler.cs
内容如下:
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;
///
/// handler 的摘要说明
///
public class handler : ihttphandler
{
    public handler()
    {
        //
        // todo: 在此处添加构造函数逻辑
        //
    }
    #region ihttphandler 成员
    public bool isreusable
    {
        get
        {
            throw new exception(the method or operation is not implemented.);
        }
    }
    public void processrequest(httpcontext context)
    {
        context.response.contenttype = text/plain;
        if (context.request.urlreferrer.host == localhost) //localhost 可以换成相应的域名等
        {
            context.response.expires = 0;
            context.response.clear();
            context.response.contenttype = image/jpg;
            context.response.writefile(context.request.physicalpath);
            context.response.end();
        }
        else
        {
            context.response.expires = 0;
            context.response.clear();
            context.response.contenttype = image/jpg;
            context.response.writefile(context.request.physicalpath + error.jpg);
            context.response.end();
        }
    }
    #endregion
}
2、在web.config中配置
3、在iis中配置
站点“属性”--》“主目录”--》“配置”--》“映射”--》“添加”
.jpg       c:/windows/microsoft.net/framework/v2.0.50727/aspnet_isapi.dll
其它类似信息

推荐信息