Home > Software engineering >  How enable Azure hosted web app to receive API calls from everywhere/wanted source?
How enable Azure hosted web app to receive API calls from everywhere/wanted source?

Time:03-01

I've developed a minimal .NET 6 API. It works fine if I run it locally from Visual Studio (If I make any API call to the endpoints it works). I've published it to Azure and haven't done any configuration. The static pages work here as well, but when I try to send a post to my wanted endpoint I get 500 Internal Server Error and from Azure I have this error: Azure Application Even Log

Do you have an idea on how I can fix this ? All the best!

CodePudding user response:

No such host is known

  • The root cause can be : DNS name resolution failure. Your application is trying to call an API URL or to connect to a service but it is not able to find the hostname or your server is not able to do DNS lookup for that hostname.
  • Enable the built-in CORS support in App Service for your API.
  • Add the below setting in your web.config file
<system.webServer>
    <httpProtocol>
        <customHeaders>
            <clear />
            <add name="Access-Control-Allow-Origin" value="*"/>
            <add name="Access-Control-Allow-Headers" value="Content-Type" />
            <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

Please refer CORS setting in Azure and Host a RESTful API with CORS in Azure App Service for more information

  • Related