Hi folks,
I have a simple class that contains some general information about the current web site :-
public class WebSiteSettings
{
public EnvironmentType Environment { get; set } // Eg. Production
public VersionType Version { get; set; } // Eg. Version2
public string ApiKey { get; set; } // Eg. ABCDE-1234
}
Now, I wish to have the following Route :-
// Api - Search methods.
routes.MapRoute(
"Search Methods",
"{versionDate}/{controller}/{action}"
);
and here's a sample url:
http://localhost.api.mydomain.com:1234/2010-01-23/search/posts?user=JonSkeet&apikey=ABCDE-1234
I currently handle retrieving the apikey via a custom ActionFilter
. That's kewl. But i'm not sure how i can extract the versiondate
(ie. 2010-01-23) from the url and populate that simple class i made .. which all controllers will have access too.
I was initially thinking of doing this:
public abstract class AbstractController : Controller
{
protected WebSiteSettings WebSiteSettings { get; set; }
protected AbstractController() : base()
{
WebSiteSettings = new WebSiteSettings();
// 1. Read in the version data and figure out the version number.
// 2. Read in the app settings to figure out the environment. (easy to do).
// 3. No api key just yet. this will be handled in the OnAuthorization action filter.
}
}
public class SearchController : AbstractController
{
public ActionResult Posts(..)
{ // ... blah ... }
}
So, i tried this and the RouteData was null, in the abstract controller. In fact, most of the information was null, in the abstract controller.
So i'm not sure when the proper place is to read in those values and create that class.
Anyone have an idea?