Disable images in ASP.NET

Last post 07-06-2009 1:39 AM by chintanpshah. 11 replies.

Sort Posts:

  • Disable images in ASP.NET

    07-03-2009, 7:12 AM
    • Member
      314 point Member
    • inbaa
    • Member since 08-19-2006, 5:08 AM
    • Posts 237

    Dear Friends ,

                        How to disable image downloading in aspx page..for example if i type http://localhost/samplesite/a.jpg.it will not allow to view a image .give your ideas

    Filed under: , ,
  • Re: Disable images in ASP.NET

    07-03-2009, 7:50 AM
    • Star
      10,362 point Star
    • chintanpshah
    • Member since 11-19-2008, 12:39 AM
    • Ahmedabad
    • Posts 1,859

    Put Images under App_Data Folder. This will not allow images to be downloaded. 

    Hope this helps...

    Don't forget to mark as answer, if it helps
  • Re: Disable images in ASP.NET

    07-03-2009, 7:54 AM
    • Star
      10,362 point Star
    • chintanpshah
    • Member since 11-19-2008, 12:39 AM
    • Ahmedabad
    • Posts 1,859

    If you use Forms authentication, deny the permission for Images folder to anonymous user.

    <location path="Images">
     <system.web>
      <authorization>
       <allow roles="Admin"/>
       <allow roles="User"/>
       <deny users="*"/>
      </authorization>
     </system.web>
    </location>

    Hope this helps...

    Don't forget to mark as answer, if it helps
  • Re: Disable images in ASP.NET

    07-04-2009, 12:44 AM
    • Member
      314 point Member
    • inbaa
    • Member since 08-19-2006, 5:08 AM
    • Posts 237

    Dear chintanpshah,

                    In my application i am using form authentication but above code not working in my application .where i go to check .

    Filed under: , ,
  • Re: Disable images in ASP.NET

    07-04-2009, 12:55 AM
    • Participant
      1,625 point Participant
    • asifchouhan
    • Member since 02-13-2009, 10:04 AM
    • India
    • Posts 295

    You can do one thing disable the right-click on mouse and show alert box


    Put the following script in the head of your page:

    <script language="Javascript">

    am = "This function is disabled!";


    bV = parseInt(navigator.appVersion)


    bNS = navigator.appName=="Netscape"


    bIE = navigator.appName=="Microsoft Internet Explorer"

    function nrc(e) {

    if (bNS && e.which > 1){

    alert(am)
    return false

    } else if (bIE && (event.button >1)) {

    alert(am)
    return false;

    }
    }


    document.onmousedown = nrc;

    if (document.layers) window.captureEvents(Event.MOUSEDOWN);

    if (bNS && bV<5) window.onmousedown = nrc;

    </script>


    Regards

    Asif
    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: Disable images in ASP.NET

    07-04-2009, 2:17 AM
    • Member
      314 point Member
    • inbaa
    • Member since 08-19-2006, 5:08 AM
    • Posts 237

    Dear asifchouhan,

             if i am directly type image name in browser that time i want to disable images view in browser(http://localhost/sample/a.jpg)


    Filed under: , ,
  • Re: Disable images in ASP.NET

    07-04-2009, 2:40 AM
    • Member
      66 point Member
    • manjeetrocks
    • Member since 06-24-2009, 10:33 AM
    • Posts 19

    <location path="UserImagesFolder">
        <system.web>
          <authorization>
            <deny users="*"/>
          </authorization>
        </system.web>
      </location>

  • Re: Disable images in ASP.NET

    07-04-2009, 3:35 AM
    • Star
      11,839 point Star
    • shahed.kazi
    • Member since 07-09-2008, 2:15 AM
    • Sydney, Australia
    • Posts 2,328

    If you stop disabling image downloading from the site - why have images in the first place. If you want to put images in an application, users can view the images and download by right clicking on the browser.

  • Re: Disable images in ASP.NET

    07-04-2009, 4:58 AM
    • Member
      314 point Member
    • inbaa
    • Member since 08-19-2006, 5:08 AM
    • Posts 237

    actually not only for image..i have a log file folder contains *.xml file .i have to stop view that log file if enter addres in browser.example http://localhost/sample/a.xml

    Filed under: , ,
  • Re: Disable images in ASP.NET

    07-04-2009, 5:07 AM
    Answer
    • Participant
      1,703 point Participant
    • hs_jha
    • Member since 01-02-2007, 7:36 PM
    • Bangalore , India
    • Posts 464

    Try this to prevent leeching -

    In web config -

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.web>
    <httpHandlers>
    <add verb="*" path="*.jpg" type="jpg, jpg"/>
    </httpHandlers>
    </system.web>
    </configuration>

    Class -:-

    using System;
    using System.Web;

    public class jpg : IHttpHandler
    {
    public void ProcessRequest(HttpContext context)
    {
    string FileName = context.Server.MapPath(context.Request.FilePath);
    if (context.Request.ServerVariables["HTTP_REFERER"] == null)
    {
    context.Response.ContentType = "image/JPEG";
    context.Response.WriteFile("/no.jpg");
    }
    else
    {
    if (context.Request.ServerVariables["HTTP_REFERER"].IndexOf("mydomain.com") > 0)
    {
    context.Response.ContentType = "image/JPEG";
    context.Response.WriteFile(FileName);
    }
    else
    {
    context.Response.ContentType = "image/JPEG";
    context.Response.WriteFile("/no.jpg");
    }
    }
    }

    public bool IsReusable
    {
    get
    {
    return true;
    }
    }

    }

  • Re: Disable images in ASP.NET

    07-04-2009, 12:17 PM
    Answer
    • Member
      172 point Member
    • rickj1
    • Member since 12-17-2007, 4:49 AM
    • Parksville B.C.
    • Posts 89

    add a web.config file to that folder and place  Manjeetrocks example

    allso check out this tutorial an access

    http://www.asp.net/learn/security/tutorial-07-vb.aspx

    don't forget to mark as answer if this helps

    Beta Junky
    www.barterlinks.net
  • Re: Disable images in ASP.NET

    07-06-2009, 1:39 AM
    Answer
    • Star
      10,362 point Star
    • chintanpshah
    • Member since 11-19-2008, 12:39 AM
    • Ahmedabad
    • Posts 1,859

    What do you mean by prevent donwloading?

    1. Disable right click on Image and save image?
    2. Type URL in Address bar?
    3. Copy from Temporaty Internet files folder?
    4. Send Web Request to download the image?

    Please let me know what you mean by prevent donwloading from above possibilities(there may be more than these)?

    Hope this helps...

    Don't forget to mark as answer, if it helps
Page 1 of 1 (12 items)