locked
Problem with files in App_Data RRS feed

  • Question

  • User-61381467 posted

    I am accessing XML files in a sub-directory DataXML. In JavaScript I am addressing them like this:

     "../DataXML/fileName.xml"

    and all is fine.

    To avoid users seeing my data files I have moved them (the files not the users!) into the ASP.NET folder, App_Data, and now get an error message when I use the form

     "../App_Data/fileName.xml" . I get the following message when I execute:

    "Failed to load data from App_Data/fileName.xml. Forbidden."

    TIA

    Friday, July 25, 2014 1:43 AM

Answers

  • User541108374 posted

    Hi,

    you can't expose these files to the browser but server side you should be able to get to them like this:

    string path = HttpContext.Server.MapPath("~/App_Data/filename.xml");

    In the past you had to also add Current to that line like HttpContext.Current....

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2014 1:53 AM
  • User541108374 posted

    Hi,

    if you want to expose files to the browser then it's a nogo to put them in the App_Data as it's protected to be downloaded from another source.

    What you can do however is to make a Web API that reads out the xml file, from the App_Data, and sends out the needed information to the widget. I didn't work with the widget myself yet but I noticed some ajax part in it so you could call your Web API with that likely.

    Update: been searching quickly in the documentation and there's a loadJSON function on the Timeline which you could likely use to call your Web API: http://simile-widgets.org/wiki/Timeline_LoadEventsDynamically

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 26, 2014 6:14 AM

All replies

  • User541108374 posted

    Hi,

    you can't expose these files to the browser but server side you should be able to get to them like this:

    string path = HttpContext.Server.MapPath("~/App_Data/filename.xml");

    In the past you had to also add Current to that line like HttpContext.Current....

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 25, 2014 1:53 AM
  • User-61381467 posted

    FYI I had to add the "Current".

    I am using the Javascript library, Simile Timeline. Does your reply mean that I have to copy my XML file from App_Data into an available directory for processing by Simile, and delete it when unloading the page?

    Or is there a better way?

    Or have I completely misunderstood??

    Regards

    Andrew McG

    Friday, July 25, 2014 7:34 PM
  • User541108374 posted

    Hi,

    if you want to expose files to the browser then it's a nogo to put them in the App_Data as it's protected to be downloaded from another source.

    What you can do however is to make a Web API that reads out the xml file, from the App_Data, and sends out the needed information to the widget. I didn't work with the widget myself yet but I noticed some ajax part in it so you could call your Web API with that likely.

    Update: been searching quickly in the documentation and there's a loadJSON function on the Timeline which you could likely use to call your Web API: http://simile-widgets.org/wiki/Timeline_LoadEventsDynamically

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 26, 2014 6:14 AM