views:

351

answers:

1

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

+2  A: 

There is no way on the server side to control which browser instance your page opens up on the client. You can't force all requests to open in the same browser window.

Also, an Application scope variable is shared by all users of your application. At least make this a Session-scope variable - otherwise you would only be allowing one user to access your portal at a time!

Honestly this sounds like a silly request from someone who a) probably doesn't understand how these types of things work and b) is trying to do an end-around for users who aren't that bright and actually see a problem with having more than one instance of your portal open.

matt b