Solved

Accessing Application object from controller

Posted on 2010-11-15
2
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 500 total points
ID: 34186242
0
 
LVL 16

Author Closing Comment

by:ToddBeaulieu
ID: 34293557
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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