集成环境下,基于HttpHandler实现:
WebConfig 增加配置:
<httpHandlers>
<add verb="*" path="*.jpg,*.jpeg,*.gif,*.png,*.bmp" type=" type="MvcApplication1.Handlers.TestHandler,MvcApplication1""/>
</httpHandlers>
c# 代码
namespace MvcApplication1.Handlers
{
public class TestHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Uri uri = context.Request.UrlReferrer;
if (uri == null)
{
context.Response.Write("来源地址不合法");
context.Response.End();
}
string host = uri.Host.ToString().ToLower();
bool result = host.IndexOf("test.com") > -1;
if (result)
context.Response.WriteFile(context.Request.PhysicalPath);
else
context.Response.Write("来源地址不合法");
}
public bool IsReusable
{
get { return true; }
}
}
}