服务器图片(绝对地址) 客户端显示问题
2011-12-07 11:26
323 查看
做个参考吧,跟之前的有个问题类似
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Handler2.ashx?path=d:/1.jpg"
alt="pic"/></div>
</form>
<asp:Image ID="Image1" runat="server"/>
</body>
</html>
handler2.ashx
<%@ WebHandler Language="C#" Class="Handler2"%>
using System;
using System.Web;
using System.IO;
using System.Drawing;
publicclass Handler2 : IHttpHandler {
publicvoid ProcessRequest(HttpContext context)
{
string path = context.Request.QueryString["path"];
if (!string.IsNullOrEmpty(path))
{
FileStream fs =new FileStream(@path, FileMode.Open, FileAccess.Read);
Bitmap myImage =new Bitmap(fs);
//输出到浏览器
MemoryStream ms =new MemoryStream();
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ClearContent();
context.Response.ContentType ="image/Jpeg";
context.Response.BinaryWrite(ms.ToArray());
}
}
publicbool IsReusable {
get {
returnfalse;
}
}
}
几个要注意的地方:
URL带有中文
页面后台代码:s
public string GoUen(object str)
{
string Result="";
if (str != null)
{
Result = Server.UrlEncode(str.ToString());
}
return Result;
}
前台调用:
<img runat="server" src= '<%#"Handler1.ashx?path="+GoUen(Eval("Address"))%>'
hasx接收时:
string path = HttpContext.Current.Server.UrlDecode(context.Request.QueryString["path"]);
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Handler2.ashx?path=d:/1.jpg"
alt="pic"/></div>
</form>
<asp:Image ID="Image1" runat="server"/>
</body>
</html>
handler2.ashx
<%@ WebHandler Language="C#" Class="Handler2"%>
using System;
using System.Web;
using System.IO;
using System.Drawing;
publicclass Handler2 : IHttpHandler {
publicvoid ProcessRequest(HttpContext context)
{
string path = context.Request.QueryString["path"];
if (!string.IsNullOrEmpty(path))
{
FileStream fs =new FileStream(@path, FileMode.Open, FileAccess.Read);
Bitmap myImage =new Bitmap(fs);
//输出到浏览器
MemoryStream ms =new MemoryStream();
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ClearContent();
context.Response.ContentType ="image/Jpeg";
context.Response.BinaryWrite(ms.ToArray());
}
}
publicbool IsReusable {
get {
returnfalse;
}
}
}
几个要注意的地方:
URL带有中文
页面后台代码:s
public string GoUen(object str)
{
string Result="";
if (str != null)
{
Result = Server.UrlEncode(str.ToString());
}
return Result;
}
前台调用:
<img runat="server" src= '<%#"Handler1.ashx?path="+GoUen(Eval("Address"))%>'
hasx接收时:
string path = HttpContext.Current.Server.UrlDecode(context.Request.QueryString["path"]);
相关文章推荐
- winfrom 客户端调用服务器ftp图片进行显示问题
- asp.net web页面显示服务器绝对路径下图片
- java下载远程http地址的图片文件到本地-自动处理图片是否经过服务器gzip压缩的问题
- JSP页面显示绝对路径图片问题
- Image显示服务器上任意绝对路径下的图片
- html的img中使用SVG图片做SRC在本地测试可用但是上传服务器后不能显示问题解决
- 微信公众号一次二次转发链接地址是IP和图片不显示,转换成文字和图片分享到朋友圈问题
- 绝对酷,如何解决asp.net中javascript脚本的问题(使用服务器控件执行客户端脚本)
- opencv显示图片地址问题
- html的img中使用SVG图片做SRC在本地测试可用但是上传服务器后不能显示问题解决 标签: SVGMIME TYPE不显示服务器设置 2016-05-21 13:49 2517人阅读 评论(0)
- webview加载https地址图片显示不出来问题
- 关于h5中图片不显示的问题之绝对路径和相对路径
- 修改MAC 在有线连接状态下显示“无效的服务器地址 BasicIPv6ValidationError”的问题
- laravel 远程服务器获取图片,解决前端显示图片跨域问题
- 绝对酷,如何解决asp.net中javascript脚本的问题(使用服务器控件执行客户端脚本)
- Nginx 配置反向代理后,页面中取绝对URL地址的问题显示代理端口
- 多张图片地址拼接使得无法显示的问题
- phpcms上传图片时,点击【上传到服务器上】按钮,显示:缺少图像源地址的解决方法
- 关于图片放在服务器上 显示的问题
- 【ZooKeeper Notes 29】 修复“ZooKeeper客户端打印当前连接的服务器地址为null”的Bug问题描述