ToddBeaulieu
asked on
Accessing Application object from controller
New to web development. Having a bit of "flow confusion".
I set an Application value in global.asax that identifies the environment (dev/test/prod).
I have a base controller that I want to expose a "CanUserEdit" property to be used by controllers, and also set an Application value for views to consume.
In my master page, I test "ViewData["CanUserEdit"]", which explodes because there is no such value.
I can't set the ViewData value in the base controller's constructor because there's no HttpContext at that point.
So, where can I hook into to set the ViewData value and how will this tie in with unit testing? I guess I'll need to be able to hand over a mock context for testing.
Thank you.
I set an Application value in global.asax that identifies the environment (dev/test/prod).
I have a base controller that I want to expose a "CanUserEdit" property to be used by controllers, and also set an Application value for views to consume.
In my master page, I test "ViewData["CanUserEdit"]",
I can't set the ViewData value in the base controller's constructor because there's no HttpContext at that point.
So, where can I hook into to set the ViewData value and how will this tie in with unit testing? I guess I'll need to be able to hand over a mock context for testing.
Thank you.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
protected override void Initialize(System.Web.Rout
{
base.Initialize(requestCon
SetViewData();
}
I'll give you the solution, though, because it was actually an interesting writeup. Thank you.