Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 13 of 13

Thread: global.asax code behind - can I use this

  1. #1
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Unhappy global.asax code behind - can I use this

    I have ver 8 ML/64 and found there is no code behind for the global.asax.

    I was just going to create a new one, since it is not possible to do Session_Start and Session_End inside an HttpModule.

    I was about to do this, but found:
    <%@ Application Inherits="AspDotNetStorefront.Global" Language="vb" %>
    in the global.asax file.

    How would I accommodate this and still be able to write my own code behind?

    According to microsoft, it is not possible to access session events from an HTTPModule, so I have no choice but a global.asax.vb code behind.

  2. #2
    John Reasons is offline Senior Member
    Join Date
    Oct 2009
    Posts
    119

    Default

    The global.asax doesn't have a code behind file by design.

    What is it your trying to build or customize? I'm curious why you feel you need a code behind file for that file.

  3. #3
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Default

    Just need to capture the following anonymous visitor data (one of many things) from the Session_Start event BEFORE (IF) they become a Customer or Add anything to the cart.
    some of which are already captured by ASPDNSF, but only when someone logs in (adds something) - that data is useless in determining page runaways, spiders, bots, crooked PPC search engines, crooked Affiliates, etc.

    ,[IPAddress]
    ,[PathInfo]
    ,[QueryStrings]
    ,[RequestMethod]
    ,[HttpHost]
    ,[HttpUserAgent]
    ,[HttpCookies]
    ,[HttpAccept]
    ,[SessionID]
    ,[PriorVisit]
    ,[AffiliateID]
    ,[Referrer]

    I built a massive internal tracking system on version 7 that took a year to perfect and hone & worked in concert with Google (but better in that does not rely on JavaScript) - just need to port it to ver 8 - global.asax is the only possible way I can see how.

    I have the source code, but really didn't want to monkey with it 5 days before going live (this is my last task)

  4. #4
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Default

    bumping this. Anyone?

  5. #5
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Default

    So much for session tracking. Geez!

  6. #6
    Rob is offline Senior Member
    Join Date
    Aug 2004
    Posts
    3,037

    Default

    we pass all of these events into AppLogic class, so you can extend/add to them there. not a big deal. you should have no problem doing what you are trying to...
    AspDotNetStorefront
    Shopping Cart

  7. #7
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Smile

    Thanks! I'll give that a try.

  8. #8
    DanV's Avatar
    DanV is offline Ursus arctos horribilis
    Join Date
    Apr 2006
    Posts
    1,568

    Default

    There are also other ways to do this Take a look at HTTPModules:


    http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

    That is how I do Exception handling and logging in the multi-store beta (to be incorporated into ML 9 as well). It is much cleaner that mucking with the global ASAX file, and you have a much lower chance of breaking things.
    Last edited by DanV; 02-18-2010 at 05:59 PM.

  9. #9
    DanV's Avatar
    DanV is offline Ursus arctos horribilis
    Join Date
    Apr 2006
    Posts
    1,568

    Default

    Seemed like a good plac for a teaser screenshot

    ... And NO, our software DOESN'T break this much. This was the result of ongoing development and testing of some new web.config management code.



    Posting some sample code in a second.
    Last edited by DanV; 02-18-2010 at 06:12 PM.

  10. #10
    DanV's Avatar
    DanV is offline Ursus arctos horribilis
    Join Date
    Apr 2006
    Posts
    1,568

    Default

    Code:
    namespace AspDotNetStorefrontEventHandlers
    {
        /// <summary>
        /// Implements methods to intercept application errors and log them appropriately
        /// </summary>
        class OnErrorHandler : IHttpModule
        {
            /// <summary>
            /// Required method responsible for loading the module
            /// </summary>
            /// <param name="app"></param>
            public void Init(HttpApplication app)
            {
                app.Error += new EventHandler(app_Error);
            }
    
            public void Dispose() { }

  11. #11
    DanV's Avatar
    DanV is offline Ursus arctos horribilis
    Join Date
    Apr 2006
    Posts
    1,568

    Default

    Plus you need some stuff in the web.config to make it work...


    Code:
        <httpModules>
    ...
          <add name="OnErrorHandler" type="AspDotNetStorefrontEventHandlers.OnErrorHandler, AspDotNetStorefrontEventHandlers" />
        </httpModules>

  12. #12
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Question

    do you know of any way to determine the start of a session in a module?
    the Application_BeginRequest fires dozens of times in a site visit.

  13. #13
    mc9000 is offline Member
    Join Date
    Aug 2007
    Posts
    83

    Default

    I thought I had it this time.
    Here's what I came up with:

    Public Sub Init(ByVal Appl As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
    Dim sessionMod As SessionStateModule = Appl.Modules("Session")
    AddHandler sessionMod.Start, AddressOf OnSessionStart
    AddHandler sessionMod.End, AddressOf OnSessionEnd
    End Sub

    Public Sub OnSessionStart(ByVal sender As Object, ByVal args As System.EventArgs)
    Dim sessionID As String = HttpContext.Current.Session.SessionID
    End Sub

    Unfortunately, SessionStart fires several times (even though the SessionID remains the same). It fires on every click in FireFox unless the user is logged in, then it fires when they log out.
    On IE it fires when they login or logout and sometimes on other pages.

    In both cases, the sessionID remains the same which means the session still only started once!

    This never happened from the global.asax file. SessionStart fired once, and only once!