0

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

1 Answer 1

0

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);

            }
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, Even with this change i got the same response. the problem is the response has the status code as 400 or 500 etc but the response did not contain status code description while using https. please check the links in the above question for response image in http vs https

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.