7

I'm trying to host my ServiceStack service in a console host. I need the ability to launch my service without administrative privileges. But when I try to do this, I get an exception "Access is denied. An unhandled exception of type 'System.Net.HttpListenerException' occurred in ServiceStack.dll".

  • There's seems to be a solution for Web API but I haven’t found such for ServiceStack.
  • I tried to do this using restrict attributes with no success.
  • I also tried solution from here, but this command requires user to have administrative privileges.

Is there any way to launch my ServiceStack self-hosted app without administrative privileges?

Community
  • 1
  • 1
Anton Anikeev
  • 163
  • 1
  • 2
  • 9
  • 3
    Have you tried using a port number higher than 1024? – Scott Aug 11 '14 at 15:11
  • @Scott I am using port number 1133. – Anton Anikeev Aug 11 '14 at 15:14
  • 2
    In that case, if a port higher than 1024 isn't working and you aren't able to use `netsh` to configure permissions then you won't be able to do it. `netsh` is the correct tool configure the port access, it requires administrative access, just once. Thereafter ServiceStack can freely access the configured port. – Scott Aug 11 '14 at 15:16
  • I have solved this problem using Web API(http://developer.greenbutton.com/self-hosting-webapi-without-administrator-privileges/) and it’s really work. But it isn’t useful for me, because my teal prefer work with ServiceStack and all services in our solution have written on it and QA used to work it. I find it more convenient. – Anton Anikeev Aug 13 '14 at 10:16
  • @Scott Yes, in my test programm I use port 8080 and it works well. But we use port higher than 1024 in our solution. – Anton Anikeev Aug 13 '14 at 10:33
  • @Scott I also use http://+:1133 and http://*:1133 with ServiceStack. Is it a bad practice? – Anton Anikeev Aug 13 '14 at 11:41
  • 1
    If you want to run without administrative privileges then the only acceptable format is `http://localhost:???` not `+` or `*` wildcards require admin rights. So what happens when you run as `http://localhost:8080` not `http://+:8080` or `http://*:8080`. – Scott Aug 13 '14 at 12:02
  • Andrey I have added this as the answer. – Scott Aug 13 '14 at 12:26
  • @Scott Sorry,maybe you misunderstood me. I meen that it is work only with Web API. Uper I have showen link with Web API sample and it is realy work(can launch services without admin privileges), but I haven't found solution for ServiceStack. I use http://+:1133 and http://*:1133 with ServiceStack for hosting with admin privileges. – Anton Anikeev Aug 13 '14 at 13:05
  • Andrey in your ServiceStack app does running with `http://localhost:1133` work without admin rights? Let establish that first. Forget about the wildcard `*` and `+` they won't work without admin rights. – Scott Aug 13 '14 at 13:24
  • @Scott no, my ServiceStack app doesn't work without admin rights. – Anton Anikeev Aug 13 '14 at 13:30
  • Andrey you keep avoiding my point. I am trying to establish if you have tried using `localhost` ... not any other hostname or wildcard, have you actually tried `localhost`? You haven't explicitly said you have. Can you update you question with your AppHost code please, because I feel like we are miscommunicating? – Scott Aug 13 '14 at 13:33
  • @Scott No, I haven't tried using localhost, but try it now. My Consolehost look like [host](https://github.com/ServiceStack/ServiceStack/wiki/Self-hosting). – Anton Anikeev Aug 13 '14 at 13:42
  • 1
    @Scott Thanks a lot. I have change *:???? on localhost:???? and **everything is working**. – Anton Anikeev Aug 13 '14 at 14:02

1 Answers1

6

To get ServiceStack running without administrative privileges you need to ensure that:

  • The host protocol is http
  • The hostname you use can only be localhost
  • You use a port number higher than 1024

So for example these hosts can be created without administrative privileges:

  • http://localhost:8000
  • http://localhost:8080
  • http://localhost:1050 ... etc.

Hostnames using wildcards, domains other than localhost, ports lower than 1024 or https require admin rights, unless a rule has been granted using netsh on Windows, or httpcfg on mono platforms.

  • http://localhost:80
  • http://+:8080
  • http://*:8080
  • http://domain.com:8080
  • http://domain.com:80
  • https://localhost:8080
Scott
  • 21,211
  • 8
  • 65
  • 72