Thoughts on img 403 forbidden, 403 forbidden

Source: Internet
Author: User

Thoughts on img 403 forbidden, 403 forbidden

Images are often displayed on webpages. For websites, some images come from the local image server. However, when the number of images increases, the disk space is a problem.

So sometimes I want to display images from other websites and directly display images from other websites on my website. However, not all Internet images can be directly connected for display.

In many cases, website developers may encounter the 403 forbidden issue. For example, to display an image from IMDB


The local localhost Debug can be displayed completely, but this error will occur after the website is deployed to the server.

// The visitor's domain var refDomain = Request. UrlReferrer. Host; // The current WebSite domain var serverDomain = Request. Url. Host;

Finally, you can determine whether the Anti HotLinking policy is determined by determining whether it comes from the same domain.

Alternatively, you can configure URLRewrite in web. config.

<rewrite><rules>  <rule name="Anti HotLinking Rule for Image" enabled="true" stopProcessing="true">  <match url=".*\.(gif|jpg|png)$" />  <conditions>    <add input="{HTTP_REFERER}" negate="true" pattern="^$" />    <add input="{HTTP_REFERER}" negate="true" pattern="*" />    <add input="{HTTP_REFERER}" negate="true" pattern="*" />  </conditions>  <action type="Rewrite" url="/images/anti-hotlinking.png" /></rule></rules></rewrite>
What if a Website user just wants to see images or videos that cannot be displayed?

Here we recommend a Chrome plug-in, Anti-HotLinking.

After installation, you will be able to see images that are not displayed.

I have not studied this plug-in carefully. It may be because Download is used to solve the Hotlinking problem, or the URL Referer can be modified through Chrome hijacking HttpRequest.


Is there any solution for website developers?

Download the Image from the Internet, convert it to base64, and transmit it to the img tag.

        public static string ImageToBase64(Stream imageStream, ImageFormat format)        {            using (System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream))            {                using (MemoryStream stream = new MemoryStream())                {                    image.Save(stream, format);                    var result = System.Convert.ToBase64String(stream.ToArray());                    return result;                }            }        }


Welcome to my personal homepage. The website is still under development .....

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: 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.