Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Sunday, February 26, 2006

A friend of mine came to me and wanted to know how to access members of global.asax in 2.0 (the big difference between 2.0 and 1.x is that the <script> statements have been applied to the file, which makes it feel a bit different). This is how (one odd thing I noted is that when I reference a member of this class from my code-behind, VS appears a bit behind the game on updating its internal references - therefore, intellisense appears missing and (once) the compiler failed to see my variable until I went back to the .asax file, re-saved it, and then went back to the .vb file!

Something feels almost counter-productive in this new direction taken with the .asax file, I'm not even sure why they did this....

In the global.asax file:

<%@ Application Language="VB" %>

<script runat="server">
   
    Public Shared Sub MyCallBackMethod()
       
    End Sub

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
    End Sub
   
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
    End Sub
       
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' 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.
    End Sub
      
</script>

In your code-behind:

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   Global.ASP.global_asax.MyCallBackMethod()
End Sub
End Class


kick it on DotNetKicks.com
Sunday, February 26, 2006 1:29:51 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing
 Saturday, February 25, 2006

    Keith posted some nice guides for Vista. Check them out here.


kick it on DotNetKicks.com
Saturday, February 25, 2006 12:12:46 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback

 Friday, February 24, 2006

...this page will be cool.


kick it on DotNetKicks.com
Friday, February 24, 2006 3:46:40 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing

Jeff has, what appears to be, a rather complete list of all events in the ASP.Net pipeline:

http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx 


kick it on DotNetKicks.com
Friday, February 24, 2006 2:11:56 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback


Okay...when I get some free time (which equates to some slow time), I'm going to write a full featured application which can generate a sitemap path by being pointed to the root folder and using some lexical analysis to identify which page is above what, etc....but for now, I needed something which (in a pure, raw fashion), just generated the XML tags for me so I could move them about freely when constructing a sitemap path, the source for my endeavor is below (it works for me, again, if it doesn't work for you - you're on your own!). The XML generated was well formatted for me (IE didn't complain when I opened it up inside it).  

using System;
using System.Collections.Generic;
using System.Text;

namespace SiteMapGenericBuilder
{
    class Program
    {
        private static System.String root = "";
        static void Recurse(System.IO.DirectoryInfo cur, System.Xml.XmlTextWriter tw)
        {
            foreach (System.IO.FileInfo fi in cur.GetFiles())
            {
                if (fi.Extension == ".aspx")
                {
                    System.String webPath = "~" + fi.FullName.Replace(root, "").Replace("\\", "/");
                    tw.WriteStartElement("siteMapNode");
                    tw.WriteAttributeString("url", webPath);
                    tw.WriteAttributeString("title", "");
                    tw.WriteAttributeString("description", "");
                    tw.WriteFullEndElement();
                }
            }
            foreach (System.IO.DirectoryInfo di in cur.GetDirectories())
                Recurse(di,tw);
        }

        static void Main(string[] args)
        {
            // this app should be placed in the root of the web application
            // (alongside the web.config file).
            System.IO.DirectoryInfo di =
                new System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
            if (System.IO.File.Exists(di.FullName + "/web.config"))
            {
                root = di.Parent.FullName;
                System.IO.FileStream fs = new System.IO.FileStream("web.sitemap.part",
                    System.IO.FileMode.Create);
                System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
                System.Xml.XmlTextWriter tw = new System.Xml.XmlTextWriter(sw);
                tw.Formatting = System.Xml.Formatting.Indented;

                // recurse over all the directories.

                tw.WriteStartDocument();
                tw.WriteStartElement("partial_sitemap");
                Recurse(di, tw);
                tw.WriteEndElement();
                tw.WriteEndDocument();
                tw.Flush();
                tw.Close();
            }
        }
    }
}


kick it on DotNetKicks.com
Friday, February 24, 2006 10:45:34 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing

Jason Haley seems to have an interesting blog - mostly a large assemblage of other interesting and notable blog entries appears to be his primary content through the "Interesting Finds" posts. Looks like a good one to check from time to time as he would probably keep us pretty aware of what's all going on... 


kick it on DotNetKicks.com
Friday, February 24, 2006 12:58:15 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing

You gotta check out the latest video from Channel9 in their Going Deep series (no, it's not porn - it's even better: it's kernel mode!). I love the concept of virtualization and I see it permeating many, many areas of computing in the future from security to testing to [insert whatever here].

Scattered, happy and maybe a bit waxed on wine I perused the internet for more content on virtualzation and hit this cool blog. Check out the whitepapers section! Wooohoo! I've identified a whole new way to kill a conversation - and it's called virtualization!


kick it on DotNetKicks.com
Friday, February 24, 2006 12:48:17 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing
 Thursday, February 23, 2006

...something wanky happens with Visual Studio when this error pops up (at least for me). It appears to lock down and hold onto some modules created in the temporary ASP.Net items folders. So, to fix this:

1) Close Visual Studio,
2) Reset iis (iisreset) - I don't think this is necessary, but it's what I did,
3) Manually remove all content under C:\windows\microsoft.net\framework\v[???]\temporary asp.net files\[webapp_name]\*

....um...whatever...


kick it on DotNetKicks.com
Thursday, February 23, 2006 6:02:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing

Computers Blogs - Blog Top Sites

Archive
<February 2006>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
2627281234
567891011
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)