简体   繁体   中英

How is an image served from a URL with an ASPX extension?

Can Somebody tell how to create such kind of urls

for example if you see the url

http://office.microsoft.com/global/images/default.aspx?assetid=ZA103873861033

you will redirect to an image ..

my question is , though this url is an image..its extension is aspx..how is it possible. how to create such kind of url's

Thanks

通过在服务器的响应中设置ContentType

  HttpContext.Response.ContentType = "image/jpeg";

This is a common method for displaying an image that's stored as a binary object in a database. One tutorial, among many, can be found here .

Essentially, what they're doing is using the aspx page to accept the URL parameter which tells them what image to fetch from the database. Then in the response they clear all output and headers, set the headers for the image, write the binary data to the response stream, and close the response stream.

So it's not really "redirecting" you to an image. The "page" being requested turns out to be an image resource in the response.

easiest way is to add generic handler *.ashx and in ashx file u'll have code behind which u can get querystring and manipulate response eg. Response.WriteFile(...)

File extensions literally have no meaning on the WWW. The thing that correctly describes the content at a particular URL is the content-type/ MIME-type . This is delivered in an HTTP header when the URL is requested prior to delivery of the main HTTP payload. Other answers describe how you might correctly set this in ASP.NET.

Aside from all other answers they may be doing a Server.Transfer() (so that you don't see it client-side) to the image file. This still means the response headers are being set to the appropriate MIME type but it also means the image isn't necesarilly coming from a database. This technique can be used to hide the actual image URL in attempts to prevent hotlinking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM