0

I have a web site in ASP.NET Core MVC, and I don't want to put my contents inside another folder. I just want to use the old school of creating this file-system architecture at the root of my project's folder:

Styles
Fonts
Scripts
Images

But I can't make ASP.NET Core MVC serving files from them. For example http://domain.test/styles/default.css returns 404.

I've tried to add StaticFileOptions, but I can't get it to work.

Can you help please?

I tried the given solution, that is, to use UseWebRoot("") with empty string to make it refer to the root of my web project. Yet it still returns 404.

I created a Styles folder inside the \bin\Debug\netcoreapp2.0\ and added a Styles.css there and it served the file.

4
  • Possible duplicate of How to Configure an Alternative Folder to wwwroot in ASP.NET Core? Commented Jan 1, 2018 at 21:17
  • The folder structure changed for a reason. It's far better an more secure to just serve static files from a single location. I'd recommend sticking with the new structure. Commented Jan 2, 2018 at 16:22
  • @ChrisPratt, that for a reason is totally logical. But not until it's flexible enough to meet business-values companies have created for themselves. We have more than 100 projects, and we're using a combination of OS and VS tools and features to centralize static content management. Story short, we save dollars (real money) and we have better productivity. Maybe in future that for a reason becomes flexible so that we also benefit from it. Commented Jan 3, 2018 at 6:44
  • ASP.NET Core is already an investment. If you're going to use it, then use it. If you don't want to change, then you're perfectly okay sticking with MVC and continuing to do things as you've always have. Commented Jan 3, 2018 at 10:34

1 Answer 1

1

If you are not adding them on the wwwroot folder then you should do more preparation.
This link will help Working with static files in ASP.NET Core

I think before asking you should search some more. For example this stackoverflow question will help you: How to Configure an Alternative Folder to wwwroot in ASP.NET Core?

1
  • I actually searched. The title of the other question is about changing wwwroot folder. I didn't approach it like that in my mind. I was thinking as how do I serve static contents like the old school of web and I was searching with that in my min. Thanks for guidance. Commented Jan 2, 2018 at 5:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.