C# - How to Run File Server without Running as Administrator?

29 views Asked by At

Problem

I am trying to host a static file server using WebApp.

When I run the following command, it throws an error.

Code

Microsoft.Owin.Hosting.WebApp.Start<WebHostStartup>("http://192.168.0.5:123");
public class WebHostStartup
{
    public void Configuration(IAppBuilder appBuilder)
    {
        var config = new HttpConfiguration();
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(name: "DefaultApi",
                                   routeTemplate: "api/{controller}/{id}",
                                   defaults: new { id = RouteParameter.Optional });
        config.Routes.MapHttpRoute(name: "ActionApi",
                                   routeTemplate: "api/{controller}/{action}/{id}",
                                   defaults: new { id = RouteParameter.Optional });
        appBuilder.MapSignalR();
        var serviceProvider = IocStartup.BuildServiceProvider();
        config.DependencyResolver = new DefaultDependencyResolver(serviceProvider);
        appBuilder.UseWebApi(config);

        var fileServerOptions = new FileServerOptions
        {
            FileSystem              = new PhysicalFileSystem(@"C:\Temp\Test"),
            RequestPath             = new PathString("/Test"),
            EnableDirectoryBrowsing = true
        };

        appBuilder.UseFileServer(fileServerOptions);
    }
}

Exceptions

Exception: TargetInvocationException - Exception has been thrown by the target of an invocation.
Inner Exception: HttpListenerException - Access is denied

What I have Tried

I can make it work by running the program as administrator.

However, this is not acceptable, as some users of this program do not have administrator access on their computers.

Question

How can I allow this to run without the need to run as admin?

Is there a Windows Setting or Firewall Rule that needs to be set?

0

There are 0 answers