【.NET】asp.net Redirect 图片路径

#需求:

  前端通过<img>的src向服务端请求图片信息,如果不存在想要的图片,那么就返回一张默认路径下的图片;

#实现:

1 <img class="related_resources" src="PictureHandle.ashx?id=42&type=thumbnail">
 1 public void ProcessRequest (HttpContext context) {
 2   string type = context.Request.QueryString["type"] != null ? context.Request.QueryString["type"].ToString() : "";
 3   string url = ConfigurationManager.AppSettings["RestUrl"] + "Resource";
 4   if (type == "thumbnail")
 5   {
 6             context.Response.ContentType = "text/plain";
 7             url = url + "/thumbnail?ID=" + id;
 8             try
 9             {
10                 bytes = new WebClient().DownloadData(url);
11                 context.Response.BinaryWrite(bytes);
12             }
13             catch(Exception)
14             {
15                  context.Response.Redirect("image/default.jpg");
16   
17             }
18     }
19 }

转载于:https://www.cnblogs.com/willingtolove/p/9604587.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值