[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Global.asax and aspx pages in subdirectories

Posted on 2006-07-22
12
Medium Priority
?
1,346 Views
Last Modified: 2012-06-21
Hello. I have this Global.asax file. It's placed on the root of my webpage. I have a problem with getting  protected void Application_BeginRequest(object sender, EventArgs e) to fire.

Aspx pages placed in the root folder, where the Global.asax file is does fire the Application_BeginRequest, but aspx pages that is in subdirectories does not fire it. Why and how to fire with these?


<%@ Application Language="C#" %>
<%@ Import Namespace="util" %>

<script runat="server">
   
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

    }
   
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }
       
    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.

    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        if (Application["LastScheduledRun"] == null)
        {
            Application["LastScheduledRun"] = DateTime.Now;
            //Label1.Text = "No send. First time." + Application["LastScheduledRun"];
            Email mail = new Email();
            mail.SendMail();
        }
        else
        {
            //Label1.Text += "Will run at first hit after 00:00 O'clock." + (((TimeSpan)(DateTime.Now - Convert.ToDateTime(Application["LastScheduledRun"]))).Minutes);
        }

        if ((((TimeSpan)(DateTime.Now - Convert.ToDateTime(Application["LastScheduledRun"]))).Minutes) > 0)
        {
            Email mail = new Email();
            mail.SendMail();

            Application.Lock();
            Application["LastScheduledRun"] = DateTime.Now;
            Application.UnLock();
            //Label1.Text = "Mail is sent at:" + Application["LastScheduledRun"];
        }        
    }
</script>
0
Comment
Question by:m-jansen
[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
  • 7
  • 5
12 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17160854
Is this 2.0 with the Web Site model or the Web Application model?

Bob
0
 

Author Comment

by:m-jansen
ID: 17161295
2.x with the Web Site model
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17161761
If you are using Server.Transfer to redirect to the page, it doesn't fire, but for Response.Redirect is does.

Bob
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:m-jansen
ID: 17167983
I thought when all kinds of all aspx pages in the project loaded/requested that Application_BeginRequestwould fire.
0
 

Author Comment

by:m-jansen
ID: 17167990
.....in the project was loaded/requested ......
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17168611
Here is a possible explanation:

Using server.Transfer() from Application_BeginRequest harm session
http://weblogs.asp.net/ngur/archive/2004/06/24/164771.aspx

Well I know it little bit twisted but If it happened to one of us, probably it could be happened to others. If for some reason you need to catch request in pipeline before page is called and you choose to use Application BeginRequest event. Using server transfer to transfer request to other page from that event will end up without session object and session cookies. Doing so you bypass regular request pipeline and simply don’t call session module who responsible for sessions handling.

You can overcome this behavior by catching application PreRequestHandlerExecute which occurred before calling handlers such as page or web service. At this pipeline step session has been initializing and you won't get session buggy behavior.

Bob
0
 

Author Comment

by:m-jansen
ID: 17169316
I don't need to redirect to another page in global.asax.... if it's that we are talking about?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17170284
No, I am talking about how you get your pages in sub-folders to show, since they are the startup page.  How are you changing to those pages?  Server.Transfer?  Response.Redirect?

Bob
0
 

Author Comment

by:m-jansen
ID: 17170369
I enter the link directly in the address field in the web browser or click on a link on a web page. (also html pages)
0
 

Author Comment

by:m-jansen
ID: 17171212
hmm, looks like all my aspx pages fire Application_BeginRequest now....
0
 

Author Comment

by:m-jansen
ID: 17171217
Think I was messing with something. Have not figured out yet what it was
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17171371
Yeah, you've got a lot of complex things going on there.

Bob
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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