The ASPX page picture is used as the URL to the IMG in HTML

Source: Internet
Author: User

Background: If you cannot directly access the server where the picture is saved, we can first make an ASPX page to accept the image sent by the server, and then the HTML page requests the ASPX page. For the image server to play a certain buffer protection, to prevent damage to the hacker attack.

Note: It is not possible to set the ImageUrl of a picture control directly in an ASPX page, this method has been experimentally unsuccessful.

1. showpic.aspx page

<%@ Page Language="C #"AutoEventWireup="true"codebehind="Showpic.aspx.cs"Inherits="Newproject.showpic" %>

2. Showpic.aspx.cs Background Code

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.IO;usingSystem.Web.UI.WebControls;usingSystem.Net;namespacenewproject{ Public Partial classShowpic:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {            //Image.imageurl = "Http://local/v1/tfs/T1.ysssTByYT1RCvBVdK";             stringURL ="Http://local/v1/tfs/T1.ysefsefsefvBVdK"; stringContenttype="application/x-www-form-urlencoded"; Stream Reqstream=Sendgetrequestforstream (Url,contenttype); MemoryStream Ms=NewMemoryStream ();            Reqstream.copyto (MS); //Response.Write (Ms. ToArray ());//This method is wrongResponse.BinaryWrite (Ms. ToArray ());//can be//HttpContext.Current.Response.BinaryWrite (Ms. ToArray ());//can be        }        PrivateStream SendGetRequest1 (stringURL) {            stringcontent; 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 was an abstractHttpWebRequest HttpWebRequest;//provides an http-specific implementation of the System.Net.WebRequest class.HttpWebResponse HttpWebResponse; //string url = "FSEFSF";HttpWebRequest = webrequest.create (URL) asHttpWebRequest; 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 () asHttpWebResponse; Stream Resstream=Httpwebresponse.getresponsestream (); using(StreamReader sr =NewStreamReader (Resstream)) {Content=Sr.            ReadToEnd (); }            returnResstream; }}}

3. pic.html page

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <title></title></Head><Body>    <Div>        <imgsrc= "Showpic.aspx"alt= "Alternate Text" />            </Div></Body></HTML>

The ASPX page picture is used as the URL to the IMG in HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.