Owin and switch user

116 views Asked by At

Having an issue with Owin (pretty new to this).

Basically, we have a windows desktop application which runs Owin and listens for requests on

static string baseAddress = "https://+:4443/";


_server = WebApp.Start<Startup>(url: baseAddress);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

using (ProcessIcon pi = new ProcessIcon())
{
    pi.Display();

    // Make sure the application runs!
    Application.Run();
}

The application runs on start up and is always listening.. all working great.

The issue is when "Switch User" happens. When the new user logs in they are presented with

Failed to listen on prefix 'https://+:4443/' because it conflicts with an existing registration on the machine.

I understand the reason why this is occurring, however, struggling to find a nice solution to resolve this without it getting messy detecting events etc.. Has anyone else experienced this?

1

There are 1 answers

0
Stefan On

Well, if the user needs to interact with the application it is user-bound. So, in your case a service wouldn't be applicable, well; for the user interaction part.

The problem here is that the port is already in use by the first user that sign in. Because the application is still running, a new user that starts the application will encounter this problem

If you are hosting a web-application, you have a couple of options:

  • Host in IIS: IIS is a windows service suited to host web applications with application pools etc. It is always running a single instance of your application
  • Split logic in 2 applications and create a service: In this scenario you'll have a windows service which does all the incomming web-app stuff and another one which interact with the user. The application that interacts with the user can communicate with the web-app through the standard http calls.
  • Subscribe to different ports for different instances. This could be a user setting for example. This provides the fastest fix in your case but might lead to issueses later on.