I’ve been asked if we can optionally “single-instance” our web portal. See this post on Hanselman's blog for the same idea in a WinForms app.
Suppose we have 2 shortcuts on the same client machine:
http://MyServer/MyWebPortal/Default.aspx?user=username&document=Foo http://MyServer/MyWebPortal/Default.aspx?user=username&document=Bar
Clicking on the first shortcut would launch our web portal, log in, and display the document “Foo”. Clicking on the second shortcut should display the document “Bar” in the running instance of the web portal.
My current approach is this: In the Page Load, for the first instance create a per-client Application variable. The second instance looks for the Application variable to see if the portal is running on the client. If it is, the second URL is recorded in another Application variable and the second instance is forcibly exited. I’ve tried creating a ASP.Net AJAX Timer to poll the Application variable for a document to display. This sort of works. In order to respond quickly to the second request I’ve set the Timer interval to 2 seconds. This makes the portal irritating to use because of the frequent postbacks.
Using my approach, is there a way for the second instance to notify the first instance to check the application variable without polling? Is there a better overall approach to this problem?
Thanks in advance