1

I am working on MVC web application, and I am using .Dlls. of some other project. That same .dll is also using in my another Web Application which is made in WebForms (.aspx) pages.

Now my question is: some function from that .dll are accepting Page.Application as a parameter. Which is working fine in .aspx page. BUT now I want to use same function in MVC application. But in MVC controller I am not able to access that Page.Application

So Please someone can help me That How can I access Page.Application in MVC Controller and Is there any equivalent of Page.Application in MVC Controller

Thanks,

EDIT:- I am not asking about Application variable - I am asking about Page.Application which is object of HttpApplicationState . I want this HttpApplicationState in MVC Controller

prog1011
  • 3,425
  • 3
  • 30
  • 57
  • You can access `Application` variables from `System.Web.HttpContext.Current.Application` since MVC controller classes not derived from `System.Web.UI.Page` unlike webforms classes have. – Tetsuya Yamamoto Apr 04 '17 at 04:49
  • @TetsuyaYamamoto - it is not about `Application variable` - `Page.Application` is object of `HttpApplicationState` . I want this `HttpApplicationState` in MVC Controller – prog1011 Apr 04 '17 at 04:52
  • There is no application state in ASP.NET MVC. The DLL you're using in webform is not applicable , you should use viewbag or viewdata since MVC is stateless unlike webforms which is managed by viewstate. – Francis Saul Apr 04 '17 at 04:57
  • 1
    You can create similar property on model class which derives `HttpApplicationState` class e.g.: `public static HttpApplicationState Application { get { return HttpContext.Current.Application; }}`. Note that `Session` and `ViewBag/ViewData` approach is more preferred ahead of application variables. – Tetsuya Yamamoto Apr 04 '17 at 04:59

2 Answers2

2

In mvc, there is no page lifecycle as in webform. Every thing from routing machanism.

While page.application, it is gets the HttpApplicationState object for the current Web request.

From MVC3 it support HttpApplicationState variable in mvc.

Check this answer :

HttpApplicationState not available in an MVC controller

Does asp.net MVC have Application variables?

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58
  • Perfect - link has the answer - HttpApplicationState application = HttpContext.ApplicationInstance.Application – prog1011 Apr 04 '17 at 08:31
0

you can use:

HttpContext.Application

and You have to add :

using System.Web;
Mahdi Shahbazi
  • 1,063
  • 1
  • 10
  • 13