使用 Azure 时如何解决此错误“AddressAccessDeniedException”?
Posted
技术标签:
【中文标题】使用 Azure 时如何解决此错误“AddressAccessDeniedException”?【英文标题】:How to solve this error "AddressAccessDeniedException" when using Azure? 【发布时间】:2017-03-24 20:01:36 【问题描述】:我有一个托管在 ASP.NET Web 应用程序中的 WCF 服务,在 Azure 中作为应用服务运行。
当我在本地机器上运行这个项目时没有错误。但是当部署到 Azure 时,出现以下错误:
[AddressAccessDeniedException: HTTP 无法注册 URL http://+:80/docs/。您的进程没有访问权限 命名空间(参见http://go.microsoft.com/fwlink/?LinkId=70353 详情)。]
关于本地机器的这个错误有很多帖子,但与 azure 无关。 Theu 建议运行 netsh 以授予 url 权限,但我不知道如何在 Azure 中执行此操作。
其实我是在尝试使用Swagger来实现WCF,错误出现在这段代码中:
Global.asax.cs:
void Application_Start(object sender, EventArgs e)
// Swagger
RouteTable.Routes.Add(new ServiceRoute("api-docs", new WebServiceHostFactory(), typeof(SwaggerWcfEndpoint)));
var swaggerHost = new WebServiceHost(typeof(SwaggerWcfEndpoint));
swaggerHost.Open();
Web.config:
<services>
<service name="SwaggerWcf.SwaggerWcfEndpoint">
<endpoint address="http://totvsrmwebapp.azurewebsites.net/docs" binding="webHttpBinding" contract="SwaggerWcf.ISwaggerWcfEndpoint" />
</service>
</services>
这里是堆栈跟踪:
'[HttpListenerException (0x5): Access is denied]
System.Net.HttpListener.SetupV2Config() +333
System.Net.HttpListener.Start() +297
System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen() +651
[AddressAccessDeniedException: HTTP could not register URL http://+:80/docs/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).]
System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen() +1473
System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener) +296
System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback) +122
System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout) +64
System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout) +67
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +61
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +136
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308
RMWCFWebApp.Global.Application_Start(Object sender, EventArgs e) +236
[HttpException (0x80004005): HTTP could not register URL http://+:80/docs/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9982013
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): HTTP could not register URL http://+:80/docs/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963380
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254'
【问题讨论】:
【参考方案1】:我已经复制了您的问题。根据我的经验,Azure Web 应用程序不允许我们注册 url “http://totvsrmwebapp.azurewebsites.net/docs”。如果你想这样做,我建议你使用 Azure 云服务,并在启动任务中执行命令 (netsh http add urlacl url=)。有关云服务的更多信息,请参阅this article。并查看this article 以了解如何使用启动任务。
【讨论】:
我也发现了这个:code.msdn.microsoft.com/CSAzureStartupTask-ebb574a0以上是关于使用 Azure 时如何解决此错误“AddressAccessDeniedException”?的主要内容,如果未能解决你的问题,请参考以下文章
使用 Terraform 部署 Azure 资源时如何解决插件错误?
解决Azure Web App 500内部服务器错误超时问题并对其进行故障排除
如何更正此 SQL 脚本中的错误(使用 Azure Datawarehouse 的数据库)