Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is it Possible to download a pdf file from a web page without showing the URL of pdf file in address bar

Is it Possible to download a pdf file from a web page without showing the URL of pdf file in address bar

Scheduled Pinned Locked Moved C#
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Puneet Bhatnagar
    wrote on last edited by
    #1

    Hi, I am working on a website and on the home page we have a pdf file link. The moment user clicks on that link the control takes the user to new URL, also displays the URL in the Address line of Browser, where the PDF file exists. However I don't want to show this URL to user, so that he can't copy and paste that URL in another browser. Is there any way possible to hide such details or is it possible to just download the pdf without showing the URL (one where PDF file actually exists) in the address line of the browser. If user is able to download also it is fine. The only thing we need is to hide the URL. Thanks in Advance!!

    G C A P 4 Replies Last reply
    0
    • P Puneet Bhatnagar

      Hi, I am working on a website and on the home page we have a pdf file link. The moment user clicks on that link the control takes the user to new URL, also displays the URL in the Address line of Browser, where the PDF file exists. However I don't want to show this URL to user, so that he can't copy and paste that URL in another browser. Is there any way possible to hide such details or is it possible to just download the pdf without showing the URL (one where PDF file actually exists) in the address line of the browser. If user is able to download also it is fine. The only thing we need is to hide the URL. Thanks in Advance!!

      G Offline
      G Offline
      Gaurav Dudeja India
      wrote on last edited by
      #2

      you can zip that pdf then user download it wirhout opening in another browser

      Gaurav Dudeja http://www.gdinfotechindia.com
      Dont be afraid of changing your life to better !

      M 1 Reply Last reply
      0
      • P Puneet Bhatnagar

        Hi, I am working on a website and on the home page we have a pdf file link. The moment user clicks on that link the control takes the user to new URL, also displays the URL in the Address line of Browser, where the PDF file exists. However I don't want to show this URL to user, so that he can't copy and paste that URL in another browser. Is there any way possible to hide such details or is it possible to just download the pdf without showing the URL (one where PDF file actually exists) in the address line of the browser. If user is able to download also it is fine. The only thing we need is to hide the URL. Thanks in Advance!!

        C Offline
        C Offline
        Covean
        wrote on last edited by
        #3

        If you are using ASP.NET you can create an aspx site where you check if the user has the right to download/see the pdf (maybe through a temp guid). If he has the right, then you can send this pdf through the response stream to the client pc. Example: .aspx

        <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetPDF.aspx.cs" Inherits="[namespace].GetPDF" %>

        .cs

        public partial class GetPDF : System.Web.UI.Page
        {
            protected void Page\_Load(object sender, EventArgs e)
            {
                try
                {
                    // check access rights or guid 
        
                    Response.Clear();
        
                    // read pdf (hosted on server site) trough binary stream to a byte array buffer
        
                    Response.ContentType = "application/pdf";
                    Response.BufferOutput = true;
                    Response.Cache.SetNoServerCaching();
                    Response.Cache.SetNoStore();
                    Response.OutputStream.Write(buffer, 0, buffer.Length);
                }
                catch (Exception)
                {
                }
            }
        }
        

        Maybe the user sees the url "http://.../GetPDF.aspx?querystring" but through your check, copy and paste the url will not work. (You could create a temp guid to access the pdf for the user, provide it in the querystring and delete this temp guid after downloading. On the next call of this url the user will not be able to download it again.) Hope this helps. Edit: In addition to the example above, you can also use the session object to check if the user has the rights to access the pdf file. Just set a session value (like Session["UserCanAccessPDF"] = true;) on link click event and check this session value on GetPDF::Page_Load. If the session value is invalid or not set, just redirect to an error page (or something else). If the value is valid, send the pdf trough the stream and delete the session value.

        Greetings Covean

        modified on Thursday, April 29, 2010 7:01 AM

        1 Reply Last reply
        0
        • G Gaurav Dudeja India

          you can zip that pdf then user download it wirhout opening in another browser

          Gaurav Dudeja http://www.gdinfotechindia.com
          Dont be afraid of changing your life to better !

          M Offline
          M Offline
          Matt Meyer
          wrote on last edited by
          #4

          You can use the Content-Disposition HTTP header to force the file to download and not open in the browser. No zipping required.

          1 Reply Last reply
          0
          • P Puneet Bhatnagar

            Hi, I am working on a website and on the home page we have a pdf file link. The moment user clicks on that link the control takes the user to new URL, also displays the URL in the Address line of Browser, where the PDF file exists. However I don't want to show this URL to user, so that he can't copy and paste that URL in another browser. Is there any way possible to hide such details or is it possible to just download the pdf without showing the URL (one where PDF file actually exists) in the address line of the browser. If user is able to download also it is fine. The only thing we need is to hide the URL. Thanks in Advance!!

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            Assuming ASP.Net... Create a button. In the click handler, write the file to the HTTP response, as the previous poster suggested. That way, you aren't using a different URL. The only way they can get the file would be to click the button. You can have whatever logic you like to decide when to display that button, or if they manage to click the button when they are not allowed, you can add additional validation to prevent the download. You could, for example, validate that the user has never downloaded the PDF before so that they can't download it a second time. If they have already downloaded it, you could show a message that says "sorry, but you are only allowed to download this PDF once". The PDF data you return can come from the server file system or from a database on the server (or even from another server). Where you want to get the PDF from is up to you.

            [Forum Guidelines]

            P 1 Reply Last reply
            0
            • A AspDotNetDev

              Assuming ASP.Net... Create a button. In the click handler, write the file to the HTTP response, as the previous poster suggested. That way, you aren't using a different URL. The only way they can get the file would be to click the button. You can have whatever logic you like to decide when to display that button, or if they manage to click the button when they are not allowed, you can add additional validation to prevent the download. You could, for example, validate that the user has never downloaded the PDF before so that they can't download it a second time. If they have already downloaded it, you could show a message that says "sorry, but you are only allowed to download this PDF once". The PDF data you return can come from the server file system or from a database on the server (or even from another server). Where you want to get the PDF from is up to you.

              [Forum Guidelines]

              P Offline
              P Offline
              PunkIsNotDead
              wrote on last edited by
              #6

              Perhaps you can use Server.Transfer("url");[^] instead of Response.Redirect("url");..... good luck ;) ;)

              A 1 Reply Last reply
              0
              • P PunkIsNotDead

                Perhaps you can use Server.Transfer("url");[^] instead of Response.Redirect("url");..... good luck ;) ;)

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                Not sure that's what the OP is after, but perhaps you should redirect your answer to the OP anyway. It's certainly going to do me no good. :rolleyes:

                [Forum Guidelines]

                1 Reply Last reply
                0
                • P Puneet Bhatnagar

                  Hi, I am working on a website and on the home page we have a pdf file link. The moment user clicks on that link the control takes the user to new URL, also displays the URL in the Address line of Browser, where the PDF file exists. However I don't want to show this URL to user, so that he can't copy and paste that URL in another browser. Is there any way possible to hide such details or is it possible to just download the pdf without showing the URL (one where PDF file actually exists) in the address line of the browser. If user is able to download also it is fine. The only thing we need is to hide the URL. Thanks in Advance!!

                  P Offline
                  P Offline
                  PunkIsNotDead
                  wrote on last edited by
                  #8

                  ups... sorry aspdotnetdev! ok! my answer was:............... Perhaps you can use Server.Transfer("url");[^] instead of Response.Redirect("url");..... good luck ;) ;)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups