aspx页面图片用作html中img的url
背景:如果无法直接访问保存图片的服务器,我们可以先制作一个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的更多相关文章
- 一个ASPX页面的生命周期?
大家都知道客户端请求一个ASPX页面,通过iis中接收,会被的interinfo.exe进程截取,判断其扩展名,再把请求转交给ASPNET_ISAPI.DLL,通过isapi扩展进入相应的管道处理,转 ...
- aspx页面 按钮不响应回车键
aspx页面在IE浏览器中,页面上的按钮默认都响应回车键,但有的时候我们的文本框可能需要响应回车键,这时我们就不想让按钮再响应回车键,这时我们只需要设置按钮的属性即可. 按钮分为两种,一种是<b ...
- 在aspx页面中使用三元表达式
第一种使用方法:判断GridView绑定的数据是否为空 用GridView或其他控件绑定数据的时候,有时候需要判断从数据库中获取的值是否是空值,然后显示相应的内容,如果在后置代码中写的话只有是在Row ...
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据
WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...
- HTML控件ID和NAME属性及在CS页面获得.ASPX页面中HTML控件的值
<转载>来自网络 一.ID是在客户端脚本里用!NAME是用于获取提交表单的某表单域信息,在form里面,如果不指定Name的话,就不会发送到服务器端,所以有name属性的控件,必须指定na ...
- 同一Session中的aspx页面的并发限制
项目中客户端采用WebBrowser展示aspx页面,用户有可能打开带多个带WebBrowser的winform窗体.此时,如果其中一个的WebBrowser的aspx页面响应较长的话,其他窗体中的W ...
- HTML控件ID和NAME属性的区别,以及如何在asp.net页面的.CS文件中获得.ASPX页面中HTML控件的值
在html中:name指的是用户名称,ID指的是用户注册是系统自动分配给用户的一个序列号. name是用来提交数据的,提供给表单用,可以重复: id则针对文档操作时候用,不能重复.如:document ...
- ASP.NET aspx页面中 写C#脚本; ASP.NET 指令(<%@%>);
1 <h2>Welcome</h2> <ul> <% for (int i = 0; i <= Convert.ToInt32(ViewData[&qu ...
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)
WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...
随机推荐
- SqlServer中把结果集放到到临时表的方法
一. SELECT INTO 1. 使用select into会自动生成临时表,不需要事先创建 select * into #temp from sysobjects 01. 把存储过程结 ...
- spring之初识Ioc&Aop
Spring框架的作用 spring是一个轻量级的企业级框架,提供了ioc容器.Aop实现.dao/orm支持.web集成等功能,目标是使现有的java EE技术更易用,并促进良好的编程习惯. Spr ...
- 使用URL访问网络资源
URL(Uniform Resource Locator)对象代表统一资源定位器,它是指向互联网“资源”的指针.资源可以是简单的文件或目录,也可以是对更复杂的对象的引用,例如对数据库或搜索引擎的查 ...
- SQL查询表占用空间大小
SQL查询表占用空间大小. create table tmp (name varchar(50),rows int,reserved varchar(50),data varchar(50),inde ...
- 判断是否是iOS8
判断是否是iOS8 //判断是否是iOS8 if ([[UIDevice currentDevice].systemVersion doubleValue]>=8.0) { NSLog(@&qu ...
- DQL查询语句内容整理
select * from t_hq_ryxx; select bianh,xingm from t_hq_ryxx; --为字段名定义别名 select bianh as 编号,xingm as 姓 ...
- android selector详解
--> 改变字体的颜色<selector xmlns:android="http://schemas.android.com/apk/res/android"> ...
- idea给web项目添加tomcat
首先,你需要新建一个web项目 生成这个样子: 我们可以新建lib文件夹用来装载必要jar,和新建classess文件夹用来存储编译后文件,这样感觉和myeclipes的项目相似. 进入项目设置,修改 ...
- SDK(SoftWare Development Kit)介绍
ctrl+alt+shift+s进入项目设置页面: SKDs的界面可以设置SDK. 点击到project 可以为project选择sdk 如上图标注 1 所示,IntelliJ IDEA 支持 6 种 ...
- STM32之RTC配置与初始化-rtc.h rtc.c
<rtc.h> #include "stm32f10x.h" #ifndef _RTC_H #define _RTC_H typedef struct { vu8 ho ...