Solved

Accessing Application object from controller

Posted on 2010-11-15
2
426 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:ToddBeaulieu
2 Comments
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 500 total points
Comment Utility
0
 
LVL 16

Author Closing Comment

by:ToddBeaulieu
Comment Utility
Actually, the solution turned out to be setting the ViewData in the Initialize event of the controller.

protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            SetViewData();
        }

I'll give you the solution, though, because it was actually an interesting writeup. Thank you.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now