1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Disable direct access of txt file on server?

Discussion in 'C#' started by Error404, Jun 15, 2009.

  1. #1
    Hello people,

    first, I'm new with ASP...

    I have a page that have some included txt contenet on it...
    I use
    <!--#include file="somefile.txt"-->
    Code (markup):
    for that,
    and it works fine, so that's cool.

    Now what I need is to disable direct opening of that somefile.txt file.

    So I want above code to work on page, as it is now, but I need to disable if someone types www.mysite.com/somefile.txt to open that file in the browser.

    So I guess I need to set something like HTTP acess for that file, but I have no clue how to do it on ASP server, so can you help me with this?..

    Or if you know any other solution for this (maybe somehow just to hide link from page source code so that visitors can't see where it is, but I think this is not possible)
     
    Error404, Jun 15, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You could rename it somefile.asp and then include that
     
    camjohnson95, Jun 15, 2009 IP
  3. DoDo Me

    DoDo Me Peon

    Messages:
    2,257
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use ISAPI Rewrite
     
    DoDo Me, Jun 16, 2009 IP
  4. Corwin

    Corwin Well-Known Member

    Messages:
    2,438
    Likes Received:
    107
    Best Answers:
    0
    Trophy Points:
    195
    #4
    Put the file in a directory, then set that directory to disable file browsing.
     
    Corwin, Jun 17, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    In addition the: <!--#include file="somefile.txt"--> code should not be visible by the user within the source code as it will be executed by the server.
     
    camjohnson95, Jun 19, 2009 IP
  6. paulv200

    paulv200 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you change the name to somefile.asp that will not display the text even if the person knows the url of the file.
     
    paulv200, Jun 27, 2009 IP
  7. zain654321

    zain654321 Peon

    Messages:
    202
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    One common cross-HTTP-server compatible method of dealing with this issue is to just stuff included files outside of the document root. So, if your pages are being served from c:/IIS/docroot/ you might make a special includes directory at c:/IIS/includes/. No one can directly access anything in your includes directory unless you're running a broken or buggy version of IIS, but your scripts should still be able to.
     
    zain654321, Jul 8, 2009 IP