In my ASP.NET MVC website people can choose between different css styles. In the future the name of these css styles will be stored in a database.
I have the following method (does not yet communicate with a database):
public FileResult CssStyle()
{
string style = "/Content/wide-site.css";
if (!String.IsNullOrWhiteSpace(style))
{
return File(style, "text/css");
}
return File("/Content/site.css", "text/css");
}
And in my _Layout.cshtml I use this line to load the stylesheet:
<link href="@Url.Action("CssStyle", "Home")" rel="stylesheet" type="text/css" />
Suppose that this CssStyle() method does a request to the database and for every page load it executes a query. What's the best way to prevent these unnecessary requests? A session perhaps?