Azure 云服务 - 拒绝访问(端口绑定)
Azure Cloud Service - Access Denied (port bind)
我正在使用 Visual Studio 2013 将 WorkerRole 发布到 Azure。 WorkerRole 应绑定到端口 80,并启动 Owin WebApp:
WebApp.Start<Startup>(new StartOptions(url: baseUri));
如果我 运行 它在 Azure 模拟器本地运行,一切正常,但是当我 运行 它运行在 Azure 上时,它会失败。相关的异常是:
Inner Exception: Access is denied
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 loggerFactory)
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDictionary`2 properties)
我尝试对实例进行 RDP 连接并添加 ACL 规则,这是本地计算机上此类错误的常见来源
netsh http add urlacl url=http://+:80/ user=Everyone
但是没有成功,还是报同样的错误。
有没有人遇到过这个问题并能指出正确的解决方向?
谢谢!
首先,在打开80端口可用的WebRole时,使用80绑定的WorkerRole是很奇怪的。
接下来。您似乎没有为 WorkerRole 定义输入端点,Azure 防火墙关闭了所有端口。因此,要打开 80 端口,请尝试在 ServiceDefinition.csdef
文件或 WorkerRole 属性 window、"Endpoints" 选项卡中指定输入端点。在发布到 Azure 时,它应该连接此配置以打开端口。
所以简而言之,请尝试使用以下内容更新您的 ServiceDefinition.csdef
:
<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="WorkerRole1">
<Endpoints>
<InputEndpoint name="HttpIn" protocol="http" port="80" localPort="80" />
</Endpoints>
</WorkerRole>
</ServiceDefinition>
另请查看这些文档:Enable Communication for Role Instances in Azure, WorkerRole Schema, How to Configure Cloud Services
希望对您有所帮助!
原来我是绑定到“*:80”,而不是从配置中正确获取 URI。因此,为 Azure Worker 获取 baseUri 绑定的正确方法是:
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"];
string baseUri = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);
然后绑定:
WebApp.Start<Startup>(new StartOptions(url: baseUri));
我正在使用 Visual Studio 2013 将 WorkerRole 发布到 Azure。 WorkerRole 应绑定到端口 80,并启动 Owin WebApp:
WebApp.Start<Startup>(new StartOptions(url: baseUri));
如果我 运行 它在 Azure 模拟器本地运行,一切正常,但是当我 运行 它运行在 Azure 上时,它会失败。相关的异常是:
Inner Exception: Access is denied
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 loggerFactory)
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDictionary`2 properties)
我尝试对实例进行 RDP 连接并添加 ACL 规则,这是本地计算机上此类错误的常见来源
netsh http add urlacl url=http://+:80/ user=Everyone
但是没有成功,还是报同样的错误。
有没有人遇到过这个问题并能指出正确的解决方向?
谢谢!
首先,在打开80端口可用的WebRole时,使用80绑定的WorkerRole是很奇怪的。
接下来。您似乎没有为 WorkerRole 定义输入端点,Azure 防火墙关闭了所有端口。因此,要打开 80 端口,请尝试在 ServiceDefinition.csdef
文件或 WorkerRole 属性 window、"Endpoints" 选项卡中指定输入端点。在发布到 Azure 时,它应该连接此配置以打开端口。
所以简而言之,请尝试使用以下内容更新您的 ServiceDefinition.csdef
:
<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="WorkerRole1">
<Endpoints>
<InputEndpoint name="HttpIn" protocol="http" port="80" localPort="80" />
</Endpoints>
</WorkerRole>
</ServiceDefinition>
另请查看这些文档:Enable Communication for Role Instances in Azure, WorkerRole Schema, How to Configure Cloud Services
希望对您有所帮助!
原来我是绑定到“*:80”,而不是从配置中正确获取 URI。因此,为 Azure Worker 获取 baseUri 绑定的正确方法是:
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"];
string baseUri = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);
然后绑定:
WebApp.Start<Startup>(new StartOptions(url: baseUri));