通过Azure Function App URL访问Swagger UI时遇未授权错误
Azure Function App访问Swagger UI时出现未授权错误
本地运行Swagger功能正常,但通过Azure URL访问时Swagger UI无法加载,且遇到未授权错误,错误截图如下:
Startup类代码
[assembly: FunctionsStartup(typeof(Startup))] namespace ADPScheduleRequestService { [ExcludeFromCodeCoverage] internal class Startup : FunctionsStartup { public override void Configure(IFunctionsHostBuilder builder) { //Register the extension builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts => { opts.SpecVersion = OpenApiSpecVersion.OpenApi3_0; opts.AddCodeParameter = true; opts.PrependOperationWithRoutePrefix = true; //opts.XmlPath = "TestFunction.xml"; opts.Documents = new[] { new SwaggerDocument { Name = "v1", Title = "ADP Schedule Request Service", Version = "v2", } }; opts.Title = "ADP"; opts.ConfigureSwaggerGen = x => { //x.OperationFilter<AuthorizationHeaderParameterOperationFilter>(); x.CustomOperationIds(apiDesc => apiDesc.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : new Guid().ToString()); }; }); } } }
Swagger Functions类代码
namespace ADPScheduleRequestService { [ExcludeFromCodeCoverage] public static class SwaggerFunctions { [SwaggerIgnore] [FunctionName("Swagger")] public static Task<HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/swagger/json")] HttpRequestMessage req, [SwashBuckleClient] ISwashBuckleClient swashBuckleClient) { return Task.FromResult(swashBuckleClient.CreateSwaggerJsonDocumentResponse(req)); } [SwaggerIgnore] [FunctionName("SwaggerUi")] public static Task<HttpResponseMessage> Run2( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/swagger/ui")] HttpRequestMessage req, [SwashBuckleClient] ISwashBuckleClient swashBuckleClient) { return Task.FromResult(swashBuckleClient.CreateSwaggerUIResponse(req, "v1/swagger/json")); } } }
内容的提问来源于stack exchange,提问作者Saksham Srivastava
相关产品推荐
相关产品推荐

