0

This is the first time I've ever developed an ASP.NET app.

I need to serve some static files from my ASP.NET 4 app. The trouble is, I want these files to appear as if they're at the root of the app, when actually they're several folders down. With ASP.NET Core this is easy; you just drop the files in the wwwroot folder, and the server treats these files as if they were at root. But my boss has asked me to use ASP.NET 4, instead of Core, if possible. So I need to figure out how to configure this.

This post and this post both answer the question I have, but I don't understand the answers that are given. Both answers tell me to add some functionality to the "ConfigureStaticFiles" method in my "Startup" class. But I don't have a Startup class.

So, what is the best way to do this in ASP.NET 4? Should I add a Startup class? If I add a Startup class, what do I do with my Global.asax? Or should I approach this some other way?

Mathew Alden
  • 1,458
  • 2
  • 15
  • 34
  • By default, IIS will serve files with registered MIME types. You don't have to configure anything for those files (for example, images, pdfs, text files, html files ect). What kind of static files are you serving? Is there security (aka, they can only be downloaded if logged in?) Your question is quite vague. – Erik Philips Jun 05 '20 at 19:30

2 Answers2

0

If you want ALL static files to be served from MVC (rather than IIS) you add this to your web.config

 <modules runAllManagedModulesForAllRequests="true">
 ...under <system.WebServer>

further read @here

Gambitier
  • 504
  • 6
  • 18
0

Okay.

I was able to use URL rewrites to make the files and folders in a specific subdirectory appear as if they were in the root folder. This answer provides an implementation for that functionality, although my app's architecture necessitated a slightly different configuration.

I don't know if URL rewrites are the best way to accomplish this functionality, but it's what I'm using for now.

Mathew Alden
  • 1,458
  • 2
  • 15
  • 34