aspx页面图片用作html中img的url
2015-04-17 16:57
435 查看
背景:如果无法直接访问保存图片的服务器,我们可以先制作一个aspx页面用来接受服务器发送过来的图片,然后html页面请求aspx页面。对图片服务器起一定的缓冲保护作用,预防对黑客攻击造成危害。
注意:不可以是直接设置aspx页面中的图片控件的imageurl,此方法已实验不成功。
1. showpic.aspx页面
2. showpic.aspx.cs 后台代码
3. pic.html 页面
注意:不可以是直接设置aspx页面中的图片控件的imageurl,此方法已实验不成功。
1. showpic.aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="showpic.aspx.cs" Inherits="NewProject.showpic" %>
2. showpic.aspx.cs 后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.IO; using System.Web.UI.WebControls; using System.Net; namespace NewProject { public partial class showpic : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Image.ImageUrl = "http://local/v1/tfs/T1.ysssTByYT1RCvBVdK"; string url = "http://local/v1/tfs/T1.ysefsefsefvBVdK"; string contentType="application/x-www-form-urlencoded"; Stream reqStream = SendGetRequestForStream(url,contentType); MemoryStream ms = new MemoryStream(); reqStream.CopyTo(ms); //Response.Write(ms.ToArray());//这种方法错误 Response.BinaryWrite(ms.ToArray());//可以 //HttpContext.Current.Response.BinaryWrite(ms.ToArray());//可以 } private Stream SendGetRequest1(string url) { string content; HttpRequest request;// Enables ASP.NET to read the HTTP values sent by a client during a Web request. WebRequest webrequest;// Makes a request to a Uniform Resource Identifier (URI). This is an abstract HttpWebRequest httpWebRequest;// Provides an HTTP-specific implementation of the System.Net.WebRequest class. HttpWebResponse httpWebResponse; //string url = "fsefsf"; httpWebRequest = WebRequest.Create(url) as HttpWebRequest; httpWebRequest.AllowAutoRedirect = true; httpWebRequest.Method = "GET"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; //httpwebrequest.ContentType = "application/json"; //httpwebrequest.ContentType = "application/xml"; //httpwebrequest.Headers.Add("url",url); httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse; Stream resStream = httpWebResponse.GetResponseStream(); using (StreamReader sr = new StreamReader(resStream)) { content = sr.ReadToEnd(); } return resStream; } } }
3. pic.html 页面
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <div> <img src="showpic.aspx" alt="Alternate Text" /> </div> </body> </html>
相关文章推荐
- php-curl获取接口图片地址,在php拼接img中无法访问,报403错误,在浏览器url中直接可以访问,html页面里img也可以访问
- jeecg如何在list页面中将img的url转化成图片展示
- 在html 使用img 和 在css中使用 background 的区别(Data URL和图片的区别)
- Java 获取前端页面代码段中img标签的src属性值,即获取图片Url
- Jsoup.connect(url).get()解析html页面空格&bsp乱码问题
- HTML基础——网站图片显示页面
- JavaScript 解析html页面中的URL字符串
- .net将动态页面(aspx)生成静态页面htm | html
- html+javascript实现图片始终在页面右下角
- jsp/html页面图片上传并展示上传的图片
- base64:URL背景图片与web页面性能优化
- chrome扩展中,content_scripts为页面css的图片的URL
- jdk8 base64 将图片转为html的img标签内容码
- IIS 500错误,能打开html页面,不能打开aspx页面,并且创建的虚拟目录无效。
- java中根据图片的url将文件回显在jsp页面代码
- php正则提取html图片(img)src地址与任意属性
- 【HTML】打开页面时按照指定的URL直接跳转到另一新页面
- 使用html2canvas对当前页面进行生成图片
- 【原】HTML页面元素加载顺序研究报告(5)----Script标签在Firefox下对背景图片的影响
- data URI scheme(图片直接保存在html页面的方法)