Solved

Accessing Application object from controller

Posted on 2010-11-15
2
431 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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