Pages

Wednesday, January 20, 2016

Enable CORS for web API 2 through Azure portal

Introduction

We can enable Cross-Origin Request (CORS) by adding “Microsoft ASP.Net Cross Origin Support” nuget package. Also we can enable CORS thorough Azure portal if we have deployed our web API 2 in azure as a app service.

Enable CORS for web API 2 through Azure portal
  1. Login to your azure portal through a browser
  2. Go to app services and click on you app service where web api 2 is hosted.
  3. Go to setting page and scroll thorough
  4. You will find API section and under that you will find CORS (I have highlighted in yellow)

cors1

  1. Click on CORS and you can add one or more your client apps. Also you can * mark to grant access to all client applications.
cors2

Tuesday, January 19, 2016

Cannot open server “” requested by the login. Client with IP address “” is not allowed to access the server issue in Azure SQL Database

Problem

I created a windows forms application in my local machine and the database was deployed in Azure. Once I try to access the database from my local machine through the application I got the exception “Cannot open server “” requested by the login. Client with IP address “” is not allowed to access the server issue”. See the screenshot.
1

Solution

Step 1. Login to Azure portal and select your database. I have used the new Azure Portal.
Step 2. Select tools on from top menu.
image
Step 3. Once you select Tools the window will be expanded and will show “Open in Visual Studio”. Select it.
image
Step 4. Then click on Configure your firewall.
image
Step 5. Give any rule name and you can give your IP address range. Note that the Client IP address is your own IP address. You can set the rage using the client IP address shown in the portal.