Skip to content

Desi banjara

  • “Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer fear, do not sit home and think about it. Go out and get busy.” Dale Carnegie Motivational & Inspirational Quotes
  • Hope your special day offers you all what your heart desires. Birthday Wishes
  • Specs comparison – CANON 1300D VS CANON 1200D Cameras
  • Motivational & Inspirational Success Quotes Inspirational Quotes
  • It’s as simple as ABC, A birthday is more fun, If you share it with me! Birthday Wishes
  • Interview question: What is the purpose of “is” operator in C#? C# development
  • How to share an account on Amazon kindle? Amazon Kindle
  • Happiness Quote – Dream as if you’ll live forever – James Dean Happiness Quote

How to enable cors in WebApi to handle request from different subdomains?

No Comments on How to enable cors in WebApi to handle request from different subdomains?

How to enable cors in WebApi to handle request from different subdomains?

I created my webApi which was hosted on different subdomain. When I was trying to access it through Angular, I was getting error with Access-Control-Allow-Origin. In my research I found I need to enable Cors to handle cross origin requests. Below is the steps to enable cors in WebApi.



Enabling CORS in WebApi

  1. Install

Install-Package Microsoft.AspNet.WebApi.Cors

  1. Update WebApiConfig.cs

using System.Web.Http;

namespace WebService

{

public static class WebApiConfig     {

public static void Register(HttpConfiguration config)

{

EnableCrossSiteRequests(config);

config.Routes.MapHttpRoute(

name: “DefaultApi”,

routeTemplate: “api/{controller}/{id}”,

defaults: new { id = RouteParameter.Optional }

);

}

private static void EnableCorsForCrossSiteRequests(HttpConfiguration config)

{

var cors = new EnableCorsAttribute(

origins: “*”,

headers: “*”,

methods: “*”);

config.EnableCors(cors);

}

 

}

}

In above code The EnableCorsAttribute is a globally scoped CORS attribute.

  1. Update your controller

[EnableCors(origins: “https://test.desibanjara.com”, headers: “*”, methods: “*”)]

[RoutePrefix(“api/ desibanjara “)]

public class TestController : ApiController

{

}

 



ASP.NET Web API, IT/Software development, Web development Tags:ASP.NET Web API, Enabling CORS, Web development, WebApi

Post navigation

Previous Post: 75 Best inspiring quotes on Leadership
Next Post: 100 + Success Quotes – Take up one idea. Make that one idea your life

Related Posts

  • Interview question: What is the use of NULL Coalescing Operator (??) in C#? Interview questions
  • C# Interview question: How encapsulation is implemented in C#? C# development
  • ASP.Net MVC Interview Questions ASP.Net MVC
  • C# interview Questions – What is struct in C#? C# development
  • What is ASP.NET Web API ? ASP.NET Web API
  • Interview question: What are primitive data types in C#? C# development

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *



Archives

  • June 2021
  • March 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • July 2020
  • June 2020
  • April 2020
  • December 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • January 2018
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • August 2015
  • May 2015
  • April 2014
  • November 2013

Categories

  • Acer
  • Amazon AWS Certification Exam
  • Amazon Kindle
  • Android phones
  • ASP.Net MVC
  • ASP.NET Web API
  • AWS DevOps Engineer Professional Exam
  • AZ-300: Microsoft Azure Architect Technologies Exam
  • Best Wishes Messages
  • birthday messages for boyfriend
  • Birthday messages For Girlfriend
  • Birthday Wishes
  • Birthday Wishes For Mom
  • Business
  • C# development
  • Cameras
  • Canon
  • Cloud
  • Cloud services
  • digital-cameras
  • Diwali
  • Entrepreneurship
  • eReaders
  • Family Quotes
  • Family Quotes
  • Friendship Quotes
  • Gadgets
  • Games
  • Get Well Soon Messages
  • GIT
  • Good Morning Wishes
  • Google
  • Gratitude Quote
  • Guru Nanak Jayanti
  • Halloween
  • Happiness Quote
  • Happy Diwali Wishes
  • Happy Independence Day Wishes
  • Happy New Year Wishes
  • HTC
  • HTC One
  • HTML
  • I Miss You Messages
  • Inspirational Quotes
  • Inspirational Travel Quotes
  • Interview questions
  • IT/Software development
  • Leadership Quote
  • Life lessons
  • Love Quotes
  • Love shayari
  • Messages
  • Microsoft AI-900 Certification Exam
  • Microsoft AZ-104 Certification Exam
  • Microsoft AZ-204 Certification Exam
  • Microsoft AZ-900 Certification Exam
  • Microsoft Azure
  • Microsoft Azure certifications
  • Microsoft Exam AZ-220
  • Microsoft Excel
  • Microsoft Office
  • Microsoft word
  • Mobile phones
  • Motivational & Inspirational Quotes
  • Nature Quotes
  • Nexus
  • Nikon
  • Pixels
  • PL-200: Microsoft Power Platform Functional Consultant Certification
  • PL-900: Microsoft Power Platform Fundamentals
  • postman
  • Quotes
  • Robin Sharma
  • Samsung Galaxy S5
  • Self improvement quotes
  • Self-Confidence Quote
  • SonarQube
  • Sony PlayStation 4
  • SQL
  • SQL Server
  • Success Quotes
  • Travel Quotes
  • Uncategorised
  • Uplifting Quotes
  • WCF (Windows Communication Foundation)
  • Web development
  • Wishes
  • Wishes for Newborn Baby

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org



Recent Posts

  • PL-200: Microsoft Power Platform Functional Consultant Certification – Exam Practice Questions
  • SonarQube – Static code analysis
  • Microsoft PL-900 Certification Exam Practice Questions – 2
  • Microsoft AZ-204 Certification Exam Practice Questions – 1
  • AWS DevOps Engineer Professional Exam Practice Questions – 14

Recent Comments

  • Yosianus on Error while sending json model in POST request to web API service using postman
  • One more year older.. Well, it is better to think another way you are just one more day older than yesterday. Have a lovely Birthday! Birthday Wishes
  • “Man cannot discover new oceans unless he has the courage to lose sight of the shore.” – Andre Gide Quotes
  • Microsoft AZ-900 Certification Exam Practice Questions – 9 Microsoft AZ-900 Certification Exam
  • Happy Birthday Wish to my mother! God has blessed our family with our mom! She had done so much for all of us now mom needs to enjoy life. Thank you Lord each day mom is with us! Birthday Wishes For Mom
  • How to take screenshot in Samsung galaxy S5 Android phones
  • I know that the most special day in your life is my birthday. But today we are celebrating the most special day in my life – Your birthday. Happy birthday mom. Birthday Wishes For Mom
  • Happy birthday to my wonderful mother! Mom I just want to wish you a happy birthday I hope you enjoy your day even though you have to work but you are surrounded by good people so I know your day will be good. I love you and I just want you to know you are the best mother anyone could ever ask for. Thanks for always being there for me through good and bad, have a wonderful day because today is your day happy birthday my beautiful friend. Birthday Wishes For Mom
  • Family Quotes – A mother’s love for her child is like nothing else Family Quotes

Copyright © 2022 Desi banjara.

Powered by PressBook News WordPress theme