Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Rerun Application_Start?

Posted on 2006-03-24
7
Medium Priority
?
494 Views
Last Modified: 2012-06-27
How would one programmatically rerun Application_Start?

Thanks!
   - Marc
0
Comment
Question by:MarcGraff
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:AGBrown
ID: 16280777
Its a tough one. Basically, as far as I know, you can't. I think the Application_Start method is kicked off by the inner workings of the HttpApplication object and its factory.

But, there is a better solution in terms of "code design" anyway; this would be to extract your code into a seperate class, and then call that class's methods from Application_Start and any other place you want it called.

Andy
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 16281302
Good Morning AGBrown,

My objective is to reload the "Application" variables. I have tryed to create a seporate class but each time it has failed.

My closest attempt:
    Public Sub ReloadVars(ByVal oGlobal As System.Web.HttpApplication)
        oGlobal.Application.Add("TestName", "TestValue")
    End Sub

but I do not know what to pass into this from the "reset" page.

Thanks!
   - Marc
0
 
LVL 12

Assisted Solution

by:AGBrown
AGBrown earned 2000 total points
ID: 16281495
Hi Marc,

Try writing your method as:

Public Sub ReloadVars()
      HttpContext.Current.Application.Add("TestName", "TestValue")
End Sub

or

Public Sub ReloadVars()
      HttpContext.Current.Application("TestName") = "TestValue"
End Sub

Note that the "Application" property in Global, or in a web page is simply a wrapper for the HttpContext.Current.Application property, so they are one and the same.

Andy
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:MarcGraff
ID: 16294442
Good day AGBrown,
I am working with the code below but it does not retain the Application variables in the global or page context. Any other suggestions?

In Global.asax.vb:
    Public Sub AppReset(ByVal bClearRecSets As Boolean, ByVal bDisplay As Boolean)
        Dim oApp As New App_Reset
        oApp.ReloadVars(bClearRecSets, bDisplay)
    End Sub


In ReloadVars:
Public Class App_Reset
    Public Sub ReloadVars(ByVal bClearRecSets As Boolean, ByVal bDisplay As Boolean)

        HttpContext.Current.Application.Add("Test", "TestValue")
   End Sub
End Class

On ResetPage:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim APP_Vars As New App_Reset
        APP_Vars.ReloadVars(False, False)
    End Sub
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 2000 total points
ID: 16299002
That's slightly confusing. I have a few ideas to find out what is happening:
1) Put a breakpoint on the line "APP_Vars.ReloadVars(False, False)" in Page_Load. Run your application in debug. When it hits, put a watch on the application object for the key "Test" (i.e. on Application("Test"). Does that value equal "TestValue"?

2) If not, then where does AppReset get called from? Do you have a call to it in the Application_Start method in the global.asax.cs? If you put a breakpoint on the line oApp.ReloadVars(bClearRecSets, bDisplay) and run your application again, does it hit?

3) Put a line of foo code after the call to ReloadVars in AppReset:

Public Sub AppReset(ByVal bClearRecSets As Boolean, ByVal bDisplay As Boolean)
        Dim oApp As New App_Reset
        oApp.ReloadVars(bClearRecSets, bDisplay)
        Dim foo As String = ""
End Sub

Put the breakpoint on Dim foo As String = "", run the application again and put a watch on Application("Test"). Does that value equal "TestValue" now? It should do. If not then something very strange is happening in your application.

Andy
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 16464086
Thanks so much Andy for all of your help! And sorry it took me so long to get this up and running!
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16465769
No problem, glad you solved it.

Andy
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Integration Management Part 2
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

579 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