首页 > 解决方案 > 将 ASP.NET 应用程序部署到 Azure Web 应用程序时出现 HTTP 500.79 错误/System.UriFormatException

问题描述

我正在尝试为 ASP.NET MVC 应用程序设置暂存环境,并希望将其作为 Azure Web 应用程序来实现,但此时我真的停留在 HTTP 500 上。

我得到的错误是:

500.79: The request failed because of an unhandled exception in the Easy Auth module.

使用诊断日志,我能够获得堆栈跟踪:

2019-01-14T13:07:22  PID[14448] Critical    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString, UriKind uriKind)
   at Microsoft.Azure.AppService.Middleware.ModuleConfig.set_OpenIdIssuer(String value)
   --- End of inner exception stack trace ---
   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 System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at Microsoft.Azure.AppService.Middleware.MiddlewareConfig.TryLoadConfig(Type type, HttpContextBase context)
   at Microsoft.Azure.AppService.Middleware.ModuleConfig.EnsureConfigLoaded(HttpContextBase context)
   --- End of inner exception stack trace ---
   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.Azure.AppService.Middleware.ModuleManager.LoadModuleConfig(HttpContextBase context)
   at Microsoft.Azure.AppService.Middleware.ModuleManager.LoadAllModulesAndGetEnabledModules(HttpContextBase context)
   at Microsoft.Azure.AppService.Middleware.HttpModuleDispatcher.EnsureInitialized(HttpContextBase context)
   at Microsoft.Azure.AppService.Middleware.HttpModuleDispatcher.<DispatchAsync>d__11.MoveNext()

我使用了在 Azure 上可以找到的任何其他诊断工具,但除了一个微弱的提示外,我无法弄清楚更多:使用失败的请求跟踪功能,我注意到这些跟踪表明请求已发出到非常奇怪且明显错误的 URL:

根据请求跟踪的 URL:https://Skillmanagementtest:80

实际请求的网址:https://skillmanagementtest.azurewebsites.net

屏幕截图:失败的请求跟踪

我完全不知道这个 URL 或端口来自哪里;我从来没有在任何地方指定端口 80(无论如何它的 HTTPS 都是错误的)。“Skillmanagementtest”是我给 Azure Web App 起的名字,我认为我没有在其他任何地方使用过它。用于身份验证的主页 URL 和回复 URL(使用 AAD 作为身份验证提供程序)设置正确。我的假设是,正是这个乱码 URL 导致了 UriFormatException,但我不知道 URL 来自哪里......

也就是说,应用程序似乎可以正常启动(还有诸如日志框架将其文件放在启动时的工作),并且启动它也不会在诊断日志中放置任何错误,但是每当发出请求时,就会发生上述错误.

在本地和生产中(使用“经典”VM,而不是 Azure Web 应用程序)Web 应用程序运行没有问题,但我无法发现它们与 Azure Web 应用程序之间的配置有任何差异(当然不同的文件除外路径和数据库连接)。还鉴于 Stack Trace 命名了一个 Azure 中间件,这表明问题源于作为 Azure Web 应用程序运行的应用程序,并且作为唯一的杠杆,我几乎拥有它应该是一些配置错误......

作为设置暂存环境的一部分,我的目标是尽可能实现自动化。因此,我还设置了一个 CI/CD resp。使用 Azure DevOps 构建和发布管道。这似乎一切正常。配置方面,我在 web.config 上分别使用 XML 转换。web.Staging.config 文件。转换都正确应用。

--

对于任何可能出现问题的想法,我将非常感激,因为我自己几乎没有东西可以尝试(第三天我正试图让这个工作......)

~ 芬罗德

标签: asp.net-mvcazureazure-web-app-serviceazure-configuration

解决方案


“解决方案”:我已经修复了这个错误,分别用不同的替换它。错误的 URL 是 App Service 的“Authenticatio / Authorization”部分中的“Issuer ID”;我填写了租户(即“xxxxx.onmicrosoft.com”)而不是颁发者 URL,如下所述:https ://docs.microsoft.com/en-us/azure/app-service/configure-authentication-provider-广告_ 但是,当我尝试向应用程序发出请求时,我现在得到了 403。将为此提出一个新问题,因为我再次不知道该怎么做,但也许有人在这里也遇到了这个问题。


推荐阅读