Self Hosted Owin and Urlacl

Self hosted OWIN and urlacl

so it turns out you need to pass in a url into StartOptions in the same format as the urlacl.

Changing the start options to the code below fixed the problem. now the app is accessible across the network.

  var options = new StartOptions("http://*:8989")
{
ServerFactory = "Microsoft.Owin.Host.HttpListener"
};

Why does Nancy need URLACL for localhost, when OWIN-self-host doesn't?

As documented here https://github.com/NancyFx/Nancy/wiki/Self-Hosting-Nancy the default behaviour is to rewrite "http://localhost:port" to http://+:port, you can disable this by passing in a

new HostConfiguration { RewriteLocalhost = false }

Running self-hosted OWIN Web API under non-admin account

It looks like the problem was with the URL reservation. I didn't need one. If there is a URL reservation, it will just prevent the owin host from starting with the access denied error. Also, the default port for owin host is 5000. If there is a "dead" process that is still running on that port, it will block your service from starting. To check you can run netstat -a -b at the command prompt.

Self Hosted OWIN Web Service - Not Listening

She solution turns out to be something seemingly unrelated.

In the Startup class, it was trying to enter A duplicate database entry and throw an exception.
However this exception was wrapped within a TargetInvocationException that was already being handled (and incorrectly consumed).

The error handling was updated and all systems are now listening on the specified port correctly.

Is it possible to expose an Owin service?

OWIN Self-Hosted apps can run on a Windows Service, as a Console process and, with if desired, as part of a more robust Host like IIS.

Since you mention your app is running as a service you're probably missing all the GUI goodies IIS provides. In reality however, IIS works on top of http.sys, just as HttpListener does (which is probably what you're using to self-host your app) 1. You just need to do some manual set up yourself:

  1. First of all, you need to make a URL reservation in order to publish on a nonstandard port.

Why would you do that? Quite simply because you're not running under localhost alone anymore on your very own local machine, where you probably are an admin and/or have special privileges/powers.

Since this is a server, and the user used for running the Service might not be an admin (most probably), then you need to give permission to that user to use that URL... and here is where URL reservations come into scene.

You pretty much have to options:

  • open up the URL to be used by any user:

     netsh http add urlacl url=http://209.111.145.73:8001/ user="everyone" listen=yes
  • or open up the URL to be used by the user(s) running the service, e.g.: NETWORK SERVICE:

     netsh http add urlacl url=http://209.111.145.73:8001/ user="NETWORK SERVICE" listen=yes

There is a way to make the reservation for several users too, using sddl, user groups, etc... but I'll not get into it (you can look that up).


  1. Second of all, you need to open up a hall through your firewall (if you don't have one on this day and age, I pity you!)

There are plenty of tutorials on this. You can use a GUI, netsh.exe and what not.

Pretty much all you need to do is make sure you allow incoming connections through that port and that should do the trick.

To make sure the hall is open through and through you can use a tool like http://www.yougetsignal.com/tools/open-ports/ and insert 209.111.145.73 in the Remote Address and 8001 in the Port Number.

If for some reason it shows that the port is closed, even after creating an incoming rule in your firewall for it, then you probably have one or more firewalls in between your server and the outside world.


With those to elements in place you should be able to access your Self-Hosted Service from the outside.

As for accessing your service through an address like http://ourpublicinfo.mydomain.com:8001, you'll need to create a DNS entry somewhere, most likely on your Domain Registrar for mydomain.com, where you could create an A Record for your ourpublicinfo subdomain pointing to 209.111.145.73.

From this point on, you should be able to access your service through direct IP and Port or through the afore mentioned URL.

Best of luck!

Note:
If your service will be access from other domains, you might need to make sure you have CORS (Cross Origen Resourece Sharing) well defined and working on your service too ;)

Owin Hosting Start Self Host

This is how I think you could do it.

    public IDisposable Start()
{
return WebApp.Start(serverUrl);
}

How to make an HTTP GET request to OWIN self hosted API?

Ok so, following the discussion in comments (helping you to debug the app).
The cross-origin security policy in browsers restricts web pages from calling an data source that exists on a different domain. A domain is either a different url, or a different port at the same url.

http://localhost:80

is a different url/domain from:

http://localhost:81

There are two solutions to this, either utilise JSONP, or CORS to make the request to the api, JSONP basically wraps your json data up in a function call. When the api call returns, it executes the callback/function call, bypassing the security restriction.
However, both JSONP and CORS require server support, which brings solution 2...

Serve up the webpage you are trying to use from the API, meaning you server it from the same domain, hence no cross-domain issues!!

Glad you have got it sorted, I know it can be frustrating with web calls.



Related Topics



Leave a reply



Submit