11

I have an application that is making use of Owin's self host functionality.

The application doesn't need administrator permissions but when I use the following code if it's not run as admin I get an exception thrown due to 'access denied'

var options = new StartOptions
{
    ServerFactory = "Microsoft.Owin.Host.HttpListener"
};
options.Urls.Add("http://+:3579/");

using (WebApp.Start<Startup>(options)) { // ..  } 

I need to provide the start options otherwise I get HTTP 503 error (See here)

Here is the exception when run as regular user (non-admin)

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)
at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(StartContext context)
at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options)
at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
at PlexRequests.UI.Program.Main(String[] args) in C:\Users\Jamie\Documents\GitHubVisualStudio\PlexRequests.Net\PlexRequests.UI\Program.cs:line 93
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Inner exception:Access is Denied

Community
  • 1
  • 1
Jamie Rees
  • 7,973
  • 2
  • 45
  • 83
  • 5
    I suppose (not tested) it's because on Windows, Owin goes down to HttpListener: https://msdn.microsoft.com/en-us/library/ms733768.aspx "Modifying the reservation rights for a portion of the namespace requires either administrative privileges or ownership of that portion of the namespace. Initially, the entire HTTP namespace belongs to the local administrator.". See also http://stackoverflow.com/questions/4019466/httplistener-access-denied – Simon Mourier Mar 22 '16 at 18:01
  • Urls overrides Port. Are you sure this is not a Firewall issue? – Jeroen Heier Mar 22 '16 at 18:25
  • This is 100% not a firewall issue – Jamie Rees Mar 23 '16 at 08:58
  • @SimonMourier Yes, that was the problem that the application required ownership of that namespace, If I add a URL reservation the problem goes away. Thanks for the assistance. – Jamie Rees Mar 23 '16 at 08:59
  • Did you have a look to the source code? https://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Hosting/ – pix Mar 24 '16 at 14:32
  • http://stackoverflow.com/questions/16642651/self-hosted-owin-and-urlacl – Mohit Verma Mar 28 '16 at 12:25

0 Answers0