Make your site run only in ONE Browser window(single instance)!
While a was at Teched2009 and watching Tim Heuer presenting Silverlight 3 I noticed a new cool feature named Local Messaging!
When I saw this new feature, a crazy idea crossed my mind. Could this be used in order to allow the user to open my website in only one browser window?
The answer is yes! But not the way I first thought. Here is how (code in MainPage.xaml.cs):
string _localName = "SL App";
bool _Close = false;
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
try
{
LocalMessageReceiver incomingMessage = new LocalMessageReceiver(_localName);
//Start listening
incomingMessage.Listen();
}
catch (ListenFailedException)
{
_Close = true;
}
}
protected void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (_Close)
{
HtmlPage.Window.SetProperty("location", "/InfoMessage.aspx");
}
else
{
LocalMessageSender msgSender = new LocalMessageSender(_localName);
msgSender.SendAsync("New instance loaded");
}
}
Loading Default.aspx
Then on the second link
Those are the files in the solution
That’s an exception driven solution but works for me! :)
This works also across different browsers but if you want you can changed to allow one instance per browser.
Enjoy!