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
Solved

Accessing Application object from controller

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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…

856 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