This project has moved. For the latest updates, please go here.

Self Hosting on Windows Server 2012 (access denied)

Jun 13, 2013 at 1:51 PM
I want to use webapi in service with windows server 2012

My url acl config is :
Reserved URL : http://+:9081/
    Listen: Yes
    Delegate: Yes
User: \Everyone
    Listen: Yes
    Delegate: Yes
    SDDL: D:(A;;GA;;;NS)(A;;GA;;;WD)
The account used by service is Network Service

The exception stack is :
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.HttpListenerException: Access is denied
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func2 appFunc, IList1 addresses, IDictionary2 capabilities)
at Microsoft.Owin.Host.HttpListener.OwinServerFactoryAttribute.Create(Func
2 app, IDictionary2 properties)
--- End of inner exception stack trace ---
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.KatanaEngine.StartServer(StartContext context)
at Microsoft.Owin.Hosting.KatanaEngine.Start(StartContext context)
at Microsoft.Owin.Hosting.WebApplication.StartImplementation(IServiceProvider services, StartOptions options, Action
1 startup)
at Microsoft.Owin.Hosting.WebApplication.Start(StartOptions options, Action`1 startup)

The code :

var options = new Microsoft.Owin.Hosting.StartOptions()
Url = "http://localhost:9081",
Verbosity = 2,
App = this.GetType().AssemblyQualifiedName,
var host = Microsoft.Owin.Hosting.WebApplication.Start(options, BuildApp);

the system works well in console mode (admin) or on windows 7 (service)
with selfhosting without owin the system also works
Jun 13, 2013 at 2:22 PM
Note that the url you provide to StartOptions must match exactly with the one you provided for the acl config (http://+:9081/).
Jun 13, 2013 at 2:59 PM
Great ! that works, thank you Tratcher