简体   繁体   中英

How to configure Https in .net core to send status code description

When using app.UseHttpsRedirection();in startup.cs and https link, The Response doesn't contain status code description

Error status code when using https image

but when app.UseHttpsRedirection(); is removed from startup.cs and using http link, The Response contains status code along with description

Required response got using http image

How to configure https or.Net Core to send status code description?

I'm using.NetCore 3.1

statup.cs

       public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "BAIM");
            });
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }

and controller method

        [HttpGet]
        public ActionResult<IEnumerable<WeatherForecast>> Get()
        {
            return BadRequest();
        }

Need the response with error code and description thanks a lot in Advance

Here is an example of sending status code in response, i am giving example of a catch block when an exception is thrown

          catch (Exception ex)
               {
               Dictionary<string, object> result = new Dictionary<string, object>();


                result["message"] = ex.Message;
                _logger.LogError(ex, "Error in Get By ID  template");

                return StatusCode(StatusCodes.Status500InternalServerError, result);

            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM