Q: ASP.NET & IronPythhon : Caching inside Global.px->Application_Start

Nov 21, 2011 at 8:57 AM

Hi,

I have a question. Webapplications in ASP.NET are capable to store
object-instances into the application-cache. There is a class in
System.Web which makes it possible : HttpContext.Application

In C# i use the Application_Start Methode in Global.asax to init an
instance of my caching-classes to enhance peformance:

void Application_Start(object sender, EventArgs e)
   {

       ........

       Application["CacheOffer"] = cchOffr;

       ........

   }

I wasn't able to make that in the Global.py IronPython ASP.NET
Application:

def Application_Start():
   ' Code that runs on application startup'
   import sys
   sys.path.append(r'c:\Python27\

Lib')
   Application["test"] = Test

Is there a way around this :

Parser Error
Description: An error occurred during the parsing of a resource
required to service this request. Please review the following specific
parse error details and modify your source file appropriately.

Parser Error Message: global name 'Application' is not defined



Thx much and kind regards
Coordinator
Nov 21, 2011 at 3:29 PM

Hi. I'm not sure what's going on here, but you might try the ironpython mailing list, ironpython-users@python.org. I added Dino and Jeff in case they are familiar with this, but I know Dino is out all week.

Bill

From: bernd_v [email removed]
Sent: Monday, November 21, 2011 1:57 AM
To: Bill Chiles
Subject: Q: ASP.NET & IronPythhon : Caching inside Global.px->Application_Start [dlr:280224]

From: bernd_v

Hi,

I have a question. Webapplications in ASP.NET are capable to store
object-instances into the application-cache. There is a class in
System.Web which makes it possible : HttpContext.Application

In C# i use the Application_Start Methode in Global.asax to init an
instance of my caching-classes to enhance peformance:

void Application_Start(object sender, EventArgs e)
{

........

Application["CacheOffer"] = cchOffr;

........

}

I wasn't able to make that in the Global.py IronPython ASP.NET
Application:

def Application_Start():
' Code that runs on application startup'
import sys
sys.path.append(r'c:\Python27\

Lib')
Application["test"] = Test

Is there a way around this :

Parser Error
Description: An error occurred during the parsing of a resource
required to service this request. Please review the following specific
parse error details and modify your source file appropriately.

Parser Error Message: global name 'Application' is not defined



Thx much and kind regards

Nov 21, 2011 at 4:13 PM
On Mon, Nov 21, 2011 at 1:57 AM, [email removed] wrote:
> Parser Error
> Description: An error occurred during the parsing of a resource
> required to service this request. Please review the following specific
> parse error details and modify your source file appropriately.
>
> Parser Error Message: global name 'Application' is not defined

I'm not sure it's the best way, but you should be able to use
System.Web.HttpContext.Current.Application['foo'] instead.

- Jeff
Nov 22, 2011 at 7:03 AM
2011/11/21 jdhardy <notifications@codeplex.com>
>
> From: jdhardy
>
> I'm not sure it's the best way, but you should be able to use
> System.Web.HttpContext.Current.Application['foo'] instead.
>
> - Jeff

Thanks Jeff. That solves my troubles.

Here is a complete working Global.py example

#  Copyright (c) Microsoft Corporation.
#
#  This source code is subject to terms and conditions of the Apache
License, Version 2.0. A
#  copy of the license can be found in the License.html file at the
root of this distribution. If
#  you cannot locate the  Apache License, Version 2.0, please send an email to
#  [email removed]. By using this source code in any fashion, you
are agreeing to be bound
#  by the terms of the Apache License, Version 2.0.
#
#  You must not remove this notice, or any other, from this software.
from cache.ch_LogCache import *
from tools.tls_UiHelper import *
from System.Web import *


def Application_Start():
    ' Code that runs on application startup'
    import sys
    sys.path.append(r'c:\Python27\Lib')
    HttpContext.Current.Application['foo'] = 'foo'

def Application_End():
    ' Code that runs on application shutdown'
    pass

def Application_Error(app, e):
    ' Code that runs when an unhandled error occurs'
    pass

def Application_BeginRequest(app, e):
    ' Code that runs at the beginning of each request'
    reqst = HttpContext.Current.Request
    pass

def Application_EndRequest(app, e):
    ' Code that runs at the end of each request'
    pass