How to Make My Data File (JSon) Available in ASP.NET Project

Viewed 263

How can I add a static data file to my web project? It doesn't work in debug mode with IIS Express, and I don't have a web site to deploy to yet.

Details

I have a data file that I want to expose on my web site. I have added that file to my ASP.NET project. When I run the project and attempt to view the file, I get a 404. In other words, I debug the project and type the file url into the browser. That url looks like 'https://localhost:44378/Data/widgetConfigMap.json'.

Rationale:

I need the data file to feed a javascript method. That method has an input parameter for a url with data, i.e. my file. The API in question is Bing Maps. The method name is 'createFromConfig'.

Unsatisfactory Alternative

I can generate the file 'on-the-fly' (via a method in my controller), but that method is slow. Slow enough that it timed-out once.

What I have tried

I tried updating the file properties. Initially, the file Build Action was 'Content', I changed that to 'Page', then to 'Resource' → neither worked. The other property choices look wrong.

Summary

I feel like there should be some way to configure my project, or IIS Express to serve-up the data file, but I can't find it.

1 Answers

It sounds like you just add the json file to your project folder instead of importing the json item into your project.

You can access json file directly when you have imported either new json item or existing json file to your /Data folder under your application.

Besides, please ensure you have let your route ignore the URL so static file handler will handle this.

enter image description here

enter image description here

Of course, you can try to publish it to local IIS not IIS express. Then import the data file and it shouldn't be limited.

Related