我正在尝试从.net编写一个WEB API,并尝试让我的Android应用程序从sql server数据库中查询一些数据.
我编写了web api,它在调试模式下运行良好.
我的问题是我注意到该应用程序的URL是localhost:port,它运行正常.但是,当我尝试将其更改为MYIP:port (eg. http:192.168.X.1234)或者MYHOSTNAME:port (eg win7home:1234)这给了我Bad Request - Invalid Hostname.
我知道我可以将其部署到IIS并且我的IIS已经设置但我只是想知道它怎么会在调试模式下不起作用???
有没有办法让我在调试模式下运行它并同时在我的Android上测试,而不是每次我想要进行更改时都要部署它?
我在VS2012中创建了一个Windows托管的SignalR集线器:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public static class SignalR
{
public static void Start()
{
const string url = "http://*:8080";
WebApp.Start<Startup>(url);
}
}
public class Broadcaster : Hub
{
public void SendDownloadResult(bool result, string device, string description, string connectionId, string task)
{
var context = GlobalHost.ConnectionManager.GetHubContext<Broadcaster>();
context.Clients.Client(connectionId).sendDownloadResult(result, device, description, task);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经在3台不同的PC上部署了这个Windows服务,它可以在两台PC上正常工作,但另一方面,当我尝试浏览时,我得到HTTP 503服务不可用 http://localhost:8080/signalr/hubs
在所有3台PC上执行代码时不会抛出异常.
我已经在添加/删除Windows功能中检查了IIS的功能,它们都是一样的.
我错过了什么?
在WEB API 2 OWIN自我主机项目中,我获得了"访问被拒绝"异常,除了localhost之外的其他任何内容:
string baseUrl = http://localhost:2500;
WebApp.Start<Startup>(baseUrl);
Run Code Online (Sandbox Code Playgroud)
如果我使用127.0.0.1或机器的实际IP地址,我会得到此异常.没有人在他们的博客中提到过这个问题,关于自托管的web api 2 owin.
这是什么问题,如何解决?
我发现这个Self托管了OWIN和urlacl,但我得到了同样的异常抛出.
我有一个使用Owin的自主功能的应用程序.
该应用程序不需要管理员权限,但是当我使用下面的代码,如果它不是作为管理员,我得到抛出因异常运行"拒绝访问"
var options = new StartOptions
{
ServerFactory = "Microsoft.Owin.Host.HttpListener"
};
options.Urls.Add("http://+:3579/");
using (WebApp.Start<Startup>(options)) { // .. }
Run Code Online (Sandbox Code Playgroud)
我需要提供启动选项,否则我会收到HTTP 503错误(请参阅此处)
这是以普通用户身份运行时的异常(非管理员)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)
at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(StartContext context)
at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options)
at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
at PlexRequests.UI.Program.Main(String[] args) …Run Code Online (Sandbox Code Playgroud) 假设提升的用户(例如,安装程序)配置了URL保留:
netsh http add urlacl url="https://+:8105/" user="SVCACCOUNT" listen=yes
Run Code Online (Sandbox Code Playgroud)
现在,当Owin启动时(在SVCACCOUNT下运行),将导致以下错误:
System.Net.HttpListenerException: Failed to listen on prefix 'http://+:8105/' because it conflicts with an existing registration on the machine.
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(..)
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(..)
...
at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
Run Code Online (Sandbox Code Playgroud)
Owin的“入口”点是:
WebApp.Start("http://+:8105", ..)
Run Code Online (Sandbox Code Playgroud)
在创建问题的过程中,我发现一个注册http://*:8105 和一个“有效”的Owin / HttpListener URL相同。
是什么阻止HttpListener(以及Owin)使用以前通过Strong Wildcard 进行的注册?
为什么*在注册和绑定中都使用(“弱通配符”)允许侦听器启动?(使用“强通配符”会引发上述错误;由于帐户访问受限,完全删除注册将导致侦听器失败并显示“访问被拒绝”。)
从哪里记录下来,从强通配符转换为弱通配符的解决方案有哪些“后果”?为何此修复程序还能起作用?从许多次询问相关问题(通常没有一个很好的答案)来看,+过去和/或在不同的系统或配置上似乎“可能起作用”:发生了什么变化?
(尽管找不到关于“冲突注册”的明确解释,但我发现有关http.sys配置的文档分散,例如“ 主机说明符类别 ”。)
如果每个System.Net.HttpListenerException删除了注册,则:无法侦听前缀'http:// localhost:8080,则Owin服务将成功启动。但是,我认为这需要更高的高度才能监听港口。
这是不是一个重复“ Owin自主机-无法监听前缀的‘http://本地主机:12345 /’,因为它与机器上的现有注册冲突 ”,因为当有问题出现仅是定义的URL保留:同样,没有其他进程在监听,这是通过netstat确认的。 …
c# ×4
owin ×3
.net ×1
android ×1
asp.net ×1
debugging ×1
http ×1
httplistener ×1
localhost ×1
permissions ×1
self-hosting ×1
signalr ×1
windows ×1