Home > Net >  ASP.NET Web API - test error : an error has occurred - how to fix it?
ASP.NET Web API - test error : an error has occurred - how to fix it?

Time:08-31

My ASP.NET Web API project works fine but when I want to run it on a server I can't pull the data. I'm using an Azure SQL database, I don't have a problem on the local server.

I can't figure out why am I getting this error

 System.InvalidOperationException: an error has occurred.   
 The given header was not found

 StackTrace    
 at System.Net.Http.Headers.HttpHeaders.GetValues(String name)    
 at RayTech.API.Security.ApiKeyHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in C:\Users\Enesray\Source\Repos\RayTechWebApi\RayTech.API\Security\ApiKeyHandler.cs:line 23 at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)     
 at System.Web.Http.HttpServer.<SendAsync>d__24.MoveNext()

web.config:

<add name="RayTechDbEntities" 
     connectionString="metadata=res://*/RayTechModel.csdl|res://*/RayTechModel.ssdl|res://*/RayTechModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*******;initial catalog=RayTechDb;user id=********;password=********;MultipleActiveResultSets=True;App=EntityFramework&quot;"  
     providerName="System.Data.EntityClient" />

Links:

  • Screenshot on local server postman: enter image description here

    Refer this msdoc on sql databse

    CodePudding user response:

    when using azure database, setting the firewall for the IP of Azure web app is required so that Azure web app can access the database.

  • Related