在非管理员帐户下运行自托管 OWIN Web API [英] Running self-hosted OWIN Web API under non-admin account

查看:26
本文介绍了在非管理员帐户下运行自托管 OWIN Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自托管 OWIN Web API 是否可以在非管理员帐户下运行?我已经尝试了几十个 url 保留,但没有任何效果.该服务无法启动并显示访问被拒绝".当帐户添加到管理员角色时它会起作用,但我不想要那样.下面的代码在 Win 7 框架 4.5.2 上运行.

Is it possible for a self-hosted OWIN Web API to run under a non-administrator account? I have already tried dozens of url reservations and nothing works. The service fails to start with "Access is denied". It works when the account is added to the administrator role but I don't want that. Code below is running on Win 7 framework 4.5.2.

//install-package microsoft.owin.hosting
//install-package Microsoft.Owin.Host.HttpListener

StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:5000/");
//options.Urls.Add(string.Format("http://{0}:5000", Environment.MachineName));
//options.Urls.Add("http://+:5000/");
//options.Urls.Add("http://*:5000/");

using (WebApp.Start<WebAPISelfHostMinimal.Startup>(options))
{
    while (!Terminate)
    {
        await Task.Delay(10); //keep cpu from getting pegged
    }

    LogUtil.LogInfo("Terminating owin host.");
}

编辑 - 这是在 Windows 帐户下运行的.

EDIT - this is running under a Windows account.

C:>netsh http add urlacl http://+:5000/ user=mini2012svcAPI

URL reservation successfully added

C:>sc start apiservice
[SC] StartService FAILED 5:

Access is denied.

C:>netsh http add urlacl http://*:5000/ user=mini2012svcAPI

URL reservation successfully added

C:>sc start apiservice
[SC] StartService FAILED 5:

Access is denied.

C:>netsh http add urlacl http://localhost:5000/ user=mini2012svcAPI

URL reservation successfully added

C:>sc start apiservice
[SC] StartService FAILED 5:

Access is denied.

推荐答案

看起来问题出在 URL 保留上.我不需要一个.如果有 URL 保留,它只会阻止 owin 主机以访问被拒绝错误启动.此外,owin 主机的默认端口是 5000.如果在该端口上仍有一个死"进程仍在运行,它将阻止您的服务启动.要进行检查,您可以在命令提示符下运行 netstat -a -b.

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.

这篇关于在非管理员帐户下运行自托管 OWIN Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆