| Bảo mật link image trong ASP.NET Có lẽ các bạn đã từng coi qua các link của vnexpress.net ? các bạn muốn tạo ra cho mình một link giống như thế với asp.net thì cùng nhau nghiên cứu Trước hết chúng ta cần khai báo trong web.config với chuỗi dữ liệu sau : Mã: Mã: namespace ImageHandler
{
public class ImageSever : IHttpHandler
{
public ImageSever()
{
//
// TODO: Add constructor logic here
//
}
public void ProcessRequest(System.Web.HttpContext context)
{
try
{
string strX = context.Request.Params["l"].ToString();
string strY = context.Request.Params["t"].ToString();
string strZ = context.Request.Params["z"].ToString();
string strPath = context.Server.MapPath(ConfigurationManager.AppSettings["MapImage"].ToString()+"lvl"+strZ+"/"+strX+"_"+strY+"_"+strZ+".png");
if(File.Exists(strPath))
{
writeImage(strPath, context);
}
else
{
//writeImage(strPath, context);
writeImage(context.Server.MapPath(ConfigurationManager.AppSettings["MapImage"].ToString()+"noimage.gif"), context);
}
}
catch (Exception objEx)
{
context.Response.Write(objEx.Message);
}
}
public bool IsReusable
{
get
{
return true;
}
}
/// public bool IsReusable public void ProcessRequest(System.Web.HttpContext context) và sau đó là cách trả về giá trị hình ảnh mà bạn cần. Chúc vui vẻ và may mắn Theo aspvn |
Bảo mật link image trong ASP.NET
Đăng ký:
Đăng Nhận xét (Atom)
0 nhận xét:
Đăng nhận xét