When you are building custom HttpModules in SharePoint a common thing to do is to use the SPContext object to get acces to your SPSite, SPWeb, SPList or SPListItem. When doing this you have to be careful because the SPContext isn’t available everywhere because HttpModules can run early in the ASP.Net request pipeline so the SPContext object isn't available yet.
if you try to acces the SPContext to early in the pipeline you’ll get a System.InvalidOperationException error.
The earliest you can use the SPContext is in the “PreRequestHandlerExecute” so don’t use it at the BeginRequest event what most people try to use when they want to add code as early in the pipeline as possible
code:
1: public class RequestHandlingHttpModule : IHttpModule, IRequiresSessionState
2: {
3:
4: public void Dispose() {}
5:
6: public void Init(HttpApplication application)
7: {
8: application.BeginRequest += application_BeginRequest;
9: application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);
10: }
11:
12: void application_PreRequestHandlerExecute(object sender, EventArgs e)
13: {
14: string webUrl = SPContext.Current.Web.Url;
15: }
16:
17: void application_BeginRequest(object sender, EventArgs e)
18: {
19: // do not use SPContext here it will throw a System.InvalidOperationException
20: // this event is fired before PreRequestHandlerExecute so code that doesn't uses SPContext goes here
21: }
22:
23: }
Geert van der Cruijsen
I think most people heard about Microsoft Surface. (If not check http://www.microsoft.com/surface/) This machine will cost around 5000 to 10000 dollars but hey it's a really cool device. Now on my daily journey surfing the internet I came across a really cool project that everyone can try at home if you have knowledge about .net and own a Nintendo Wii to create your own multi touch user interface!
Since the Wii remote is using a Bluetooth connection towards it’s remote it’s also possible to connect it to your own pc. The Wii remote has an infra red sensor which can sense multiple infra red light sources at the same time.
How this all works is explained at http://www.cs.cmu.edu/~johnny/projects/wii/
There is also a C# sample code how to connect your pc to your Wii remote and how you’re able to do cool stuff with it. If I have enough time in the coming weeks I’ll try to test it myself if I can get my hands on some infra red LED’s.
Have fun!
Geert van der Cruijsen