背景:如果无法直接访问保存图片的服务器,我们可以先制作一个aspx页面用来接受服务器发送过来的图片,然后html页面请求aspx页面。对图片服务器起一定的缓冲保护作用,预防对黑客攻击造成危害。

注意:不可以是直接设置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>

aspx页面图片用作html中img的url的更多相关文章

  1. 一个ASPX页面的生命周期?

    大家都知道客户端请求一个ASPX页面,通过iis中接收,会被的interinfo.exe进程截取,判断其扩展名,再把请求转交给ASPNET_ISAPI.DLL,通过isapi扩展进入相应的管道处理,转 ...

  2. aspx页面 按钮不响应回车键

    aspx页面在IE浏览器中,页面上的按钮默认都响应回车键,但有的时候我们的文本框可能需要响应回车键,这时我们就不想让按钮再响应回车键,这时我们只需要设置按钮的属性即可. 按钮分为两种,一种是<b ...

  3. 在aspx页面中使用三元表达式

    第一种使用方法:判断GridView绑定的数据是否为空 用GridView或其他控件绑定数据的时候,有时候需要判断从数据库中获取的值是否是空值,然后显示相应的内容,如果在后置代码中写的话只有是在Row ...

  4. WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据

    WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...

  5. HTML控件ID和NAME属性及在CS页面获得.ASPX页面中HTML控件的值

    <转载>来自网络 一.ID是在客户端脚本里用!NAME是用于获取提交表单的某表单域信息,在form里面,如果不指定Name的话,就不会发送到服务器端,所以有name属性的控件,必须指定na ...

  6. 同一Session中的aspx页面的并发限制

    项目中客户端采用WebBrowser展示aspx页面,用户有可能打开带多个带WebBrowser的winform窗体.此时,如果其中一个的WebBrowser的aspx页面响应较长的话,其他窗体中的W ...

  7. HTML控件ID和NAME属性的区别,以及如何在asp.net页面的.CS文件中获得.ASPX页面中HTML控件的值

    在html中:name指的是用户名称,ID指的是用户注册是系统自动分配给用户的一个序列号. name是用来提交数据的,提供给表单用,可以重复: id则针对文档操作时候用,不能重复.如:document ...

  8. ASP.NET aspx页面中 写C#脚本; ASP.NET 指令(<%@%>);

    1 <h2>Welcome</h2> <ul> <% for (int i = 0; i <= Convert.ToInt32(ViewData[&qu ...

  9. WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)

    WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...

随机推荐

  1. OID,主键生成策略,PO VO DTO,get和load区别,脏检查,快照,java对象的三种状态

    主键生成策略 sequence 数据库端 native 数据库端 uuid  程序端 自动赋值 生成的是一个32位的16进制数  实体类需把ID改成String 类型 assigned  程序端 需手 ...

  2. sqlserver 修改替换text,ntext类型字段的两种方案

    方案一 用Update和Replace --替换语句(因为varchar(max)最大值是8000,所以大于8000的部分会被截掉) UPDATE dbo.SNS_UserBlog SET [Desc ...

  3. QQ输入法评价

    用户界面: 用户可以通过登录QQ展现自己的QQ头像,可以点击头像显示用户信息,可以中英文切换,全半角切换,打开属性设置,以为软键盘 记住用户选择: 当用户使用QQ输入法时,QQ输入法可以记住用户当前的 ...

  4. HDU 5773 The All-purpose Zero 求LIS

    求最长上升子序列长度: 单纯的dp时间复杂度是O(n*n)的 dp[i] = max(dp[j]+1); (0=<j<=i-1 && a[i]>a[j]) 用二分可以 ...

  5. sqlserver 2008 左补齐字符串

    SQLServer:right函数 语法 Right(string, length)   Right 函数的语法具有下面的命名参数:   部分 说明 string 必要参数.字符串表达式,从中最右边的 ...

  6. c++ 普通高精乘

    //第一次提交全错了,太过相信自己了. //给我教训是注意循环后变量的值,和pascal不一样. //就不贴错误代码了. //codevs3118 高精度练习之除法 #include<cstdi ...

  7. UVa 11427 - Expect the Expected

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. 简单探索ContentProviderOperation

    前面一片文章中用到了ContentProviderOperation,那么我们就来看看ContentProviderOperation到底是怎么工作的. 1. ContentProviderOpera ...

  9. SQL 插入日期时间 变量值

    --看看吧^^ CREATE TABLE #temp ( test datetime ) go --SQL: INSERT #temp SELECT 1.1 UNION ALL GO --SQL: I ...

  10. 数据结构-Vector

    自定义Vector实现: /////////////////////////////////////////////////////////////////////////////// // // F ...