locked
Owin.Hosting.StartOptions Access localhost without admin permissions. RRS feed

  • Question

  • User846413324 posted

    I have an application which hosts a local website with the Microsoft.Owin.StaticFiles namespace. Using http://localhost:*port*/ form local computer works totally fine. Unfortunately when trying to connect with http://*localip*:*port*/ it shows me a "HTTP Error 503". I am aware that using a wildcard domain like "http://*:25874/" is possible to solve this issue but this requires admin privileges which is not an option for my case.

    I am wondering if there is a workaround for this issue by using for example host header rewrites or different techniques.

    Hope that somebody here can help me with this. Thank you very much in advance.

    Thursday, July 20, 2017 9:47 AM

All replies

  • User1771544211 posted

    Hi PPAndi,

    Do you set your Microsoft.Owin.StaticFiles web app to listen to the localhost url like the following?

        var url = "http://localhost:8080";
        var root = args.Length > 0 ? args[0] : ".";
        var fileSystem = new PhysicalFileSystem(root);
     
        var options = new FileServerOptions
        {
            EnableDirectoryBrowsing = true, 
            FileSystem = fileSystem                             
        };
     
        WebApp.Start(url, builder => builder.UseFileServer(options));  

    If so, you should change the code to make it listen to the ipaddress instead of localhost.

    Best Regards,

    Jean

    Tuesday, July 25, 2017 3:06 AM
  • User846413324 posted

    Hi Jean,

    thank you for the response. I was able to make it listen to every ipadress with "http://*:8080/".

    Unfortunately the dealbreaker for me is that it requires admin privileges.

    Is there any workaround to listen to every ip address without the need for admin privileges?

    Tuesday, July 25, 2017 11:08 AM
  • User1771544211 posted

    Hi PPAndi,

    Is there any workaround to listen to every ip address without the need for admin privileges?

    Please try the following command:

    netsh http add urlacl url=http://*:8080/ user=MyUser 

    And a similar issue is discussed here : https://stackoverflow.com/questions/24976425/running-self-hosted-owin-web-api-under-non-admin-account

    Best Regards,

    Jean

    Wednesday, July 26, 2017 7:47 AM
  • User846413324 posted

    I tried this as well. When you try it with an non-admin cmd you will see the following error message in Windows 10.

    Url reservation add failed, Error: 5
    The requested operation requires elevation (Run as administrator).

    Wednesday, July 26, 2017 8:30 AM
  • User1771544211 posted

    Hi PPAndi,

    When you try it with an non-admin cmd you will see the following error message in Windows 10.

    Yes, to run this command you need to run the cmd as admin.

    Do you mean that you can't run the cmd as admin due to some reasons?

    Best Regards,

    Jean

    Wednesday, July 26, 2017 8:37 AM
  • User846413324 posted

    Yes, because I deploy a clickonce application which runs under user scope. I tested a small .net web-server a few weeks ago and I was able to connect to it without admin rights or special ip bindings. So I think it is a problem with Owin/Katana.

    Wednesday, July 26, 2017 8:52 AM
  • User1771544211 posted

    Hi PPAndi,

    Yes, because I deploy a clickonce application which runs under user scope.

    To run the self host application using Owin, you may need to register the URLs that used for the self host application.

    However, register the urls needs the Admin permission. I think that's why it needs admin rights to set the application with Owin.

    Best Regards,

    Jean

    Thursday, July 27, 2017 8:08 AM