招摇未显示在Azure上

时间:2019-10-12 17:53:49

标签: c# azure swagger

我有以下启动文件:

    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });


        services.AddMvc()
            .AddFluentValidation()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info
            {
                Title = "Name Application Api",
                Version = "v1",
                Contact = new Contact
                {
                    Name = "A B",
                    Email = "email@email.com"
                }
            });

            c.DescribeAllEnumsAsStrings();
            c.DescribeStringEnumsInCamelCase();

            //c.OperationFilter<SwaggerAuthResponsesOperationFilter>();

            // Set the comments path for the Swagger JSON and UI.
            var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
            c.IncludeXmlComments(xmlPath);

            // enable the annotations on Controller classes [SwaggerTag]
            c.EnableAnnotations();
        });

        services.AddMvcCore().AddApiExplorer();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        app.UseSwagger();

        // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), 
        // specifying the Swagger JSON endpoint.
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "Support Application API V1");
            c.DocumentTitle = "Support Application Api";
        });
    }

当我尝试在本地https://localhost:44341/swagger/index.html上打开打开页面时,效果很好 但是,当我将其发布到Azure时,我会得到

  

此页面无效

     

drugalcohol.azurewebsites.net当前无法处理此问题   请求。

     

HTTP错误500

服务计划是B1定价级别。

怎么了?

1 个答案:

答案 0 :(得分:1)

您的项目中似乎未配置XML生成步骤,这就是为什么在代码行c.IncludeXmlComments(xmlPath);执行时,应用程序将以Http 500状态代码进行响应的原因。

要生成XML注释,您需要确保选中项目的build属性中的“ XML文档文件”选项。

enter image description here