What is the ASP.NET Core convention for static, non-MVC pages?

Viewed 41

I'm converting my website from Web Forms to .NET Core. I don't want to change the directory level of various files, e.g.:

MYDOMAIN.com/FAQ.html
MYDOMAIN.com/Privacy.html

By using the UseStaticFiles() middleware, I can place these in the wwwroot folder and they will be served as is. However, I don't know how to apply a Layout page with my website theme to those files since they're outside of the MVC framework.

I'd like to leverage the Layout files and MVC framework by using .cshtml files, but I'm also trying to avoid the extra controller directory that's imposed on the URL:

MYDOMAIN.com/home/FAQ.html
MYDOMAIN.com/home/Privacy.html

Maybe this is short-sighted, but how do developers handle this?

And actually, my existing files are .aspx at the moment, not .html files so that adds another level of confusion as to what the convention is for migrating to .Net Core. Should I use any .aspx files anywhere in the project or should they all be converted to .cshtml / .html files? Or something else?

1 Answers

I have successfully implemented a solution, but it's kind of a hack. I add controllers for each static page, for example I created both a FAQController.cs and PrivacyController.cs.

Each controller has only Index() actions so that they can take advantage of _Layout.cshtml and _ViewStart.cshtml.

It seems like a roundabout way to go just to move the following up one level e.g.

MYDOMAIN.com/FAQ
MYDOMAIN.com/Privacy

but it works.

Related