question

Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 asked Jitheshkr-7917 answered

Asp.Net Core API published. Default page getting 500 error but Weatherforcast api working in Postman.

Asp.Net Core Api published in IIS.
default page swagger/index.html not working and Login modules not working. but Weatherforcast api working in Postman. Please help.

dotnet-aspnet-core-generaldotnet-aspnet-core-webapi
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Whether this error happens in the local environment?

Open the F12 developer Console tool and click on the swagger.json link, and check the detail error message. Refer to this thread.

Generally, this error might relate that there have multiple get/post method in the same controller, you can check it and try to use the HttpGet and HttpPost attribute to set the different template name. If the issue not relate it, you'd better to share the relates code or create a simple sample to reproduce the problem.

0 Votes 0 ·
rijwanansari avatar image
0 Votes"
rijwanansari answered

Hi @Jitheshkr-7917

I think this is because of environment.

 // Configure the HTTP request pipeline.
 if (app.Environment.IsDevelopment())
 {
     app.UseSwagger();
     app.UseSwaggerUI();
 }

You can keep swagger UI call outside of development environment.

Try this way and check

 // Configure the HTTP request pipeline.
 if (app.Environment.IsDevelopment())
 {
        
 }
 app.UseSwagger();
 app.UseSwaggerUI();



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 answered

Whether this error happens in the local environment? No. Local environment it's working fine.
But when I publish to the local IIS, it's not working.
the same IIS url when I called in Postman, wheatherforcast api is working.
Other default swagger/index.html and Authenticate api's are not working. please help.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 answered rijwanansari commented

thanks. When I manually added the "swagger/index.html" the page is showing without error.
The main issue is still remain. The /api/Authenticate/register getting 500 error.
Please help

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Jitheshkr-7917

Are you getting this error while making the API call or loading the swagger file?

0 Votes 0 ·
Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 answered

while making the API call getting 500 error

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 answered Jitheshkr-7917 published

Hi @rijwanansari ,

My appsettings.json is

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"default": "Server=.;Database=AngularGYMDB;Integrated Security=true;"
},
"JWT": {
"ValidAudience": "http://localhost:90",
"ValidIssuer": "http://localhost:90",
"Secret": "ByYM000OLlMQG6VVVp1OH7Xzyr7gHuw1qvUC5dcGt3SNM"
}
}


and my startup.cs

using CoreApiAuth.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreApiAuth
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

     public IConfiguration Configuration { get; }

     // This method gets called by the runtime. Use this method to add services to the container.
     public void ConfigureServices(IServiceCollection services)
     {

         services.AddControllers();
         services.AddSwaggerGen(c =>
         {
             c.SwaggerDoc("v1", new OpenApiInfo { Title = "CoreApiAuth", Version = "v1" });
         });

         // For Entity Framework  
         services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("default")));

         // For Identity  
         services.AddIdentity<ApplicationUser, IdentityRole>()
             .AddEntityFrameworkStores<ApplicationDbContext>()
             .AddDefaultTokenProviders();

         // Adding Authentication  
         services.AddAuthentication(options =>
         {
             options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
             options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
             options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
         })

         // Adding Jwt Bearer  
         .AddJwtBearer(options =>
         {
             options.SaveToken = true;
             options.RequireHttpsMetadata = false;
             options.TokenValidationParameters = new TokenValidationParameters()
             {
                 ValidateIssuer = true,
                 ValidateAudience = true,
                 ValidAudience = Configuration["JWT:ValidAudience"],
                 ValidIssuer = Configuration["JWT:ValidIssuer"],
                 IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT:Secret"]))
             };
         });
     }

     // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
     {

         if (env.IsDevelopment())
         {
             app.UseDeveloperExceptionPage();
              
         } 
            
         app.UseSwagger();
             app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CoreApiAuth v1"));

         if (env.IsDevelopment())
         {
             app.UseDeveloperExceptionPage();
         }

         //app.UseHttpsRedirection();

         app.UseRouting();

         app.UseAuthentication();

         app.UseAuthorization();

         app.UseEndpoints(endpoints =>
         {
             endpoints.MapControllers();
         });

     }
 }

}

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

rijwanansari avatar image
0 Votes"
rijwanansari answered

In that case, you should check application logger. If you are using Azure App Service then you can use diagnostic. This is internal server error, you need to debug the solution

173518-image.png



image.png (36.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 answered

Hi @rijwanansari , the application is working through visual studio. but iis showing the 500 error. Where I can find the error log.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

rijwanansari avatar image
0 Votes"
rijwanansari answered

You can check IIS log for more details

173522-image.png

Additinally, ASP.NET exceptions in Window Event Viewer

173450-image.png



image.png (99.1 KiB)
image.png (248.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jitheshkr-7917 avatar image
1 Vote"
Jitheshkr-7917 answered

thanks. resolved the issue.
I used the connection string as Integrated secuity = True. When I changed to Sql Authentication, it's worked.
Once again thanks..

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jitheshkr-7917 avatar image
0 Votes"
Jitheshkr-7917 answered

Hi @rijwanansari thanks your support.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.