Introduction

In this article, I will explain how to use the Package "Microsoft.AspNet.Cors" from the nightly builds.

Nightly Build is a framework. We strongly advise that it should only used for official builds for production. It is used by the developers for fixing the bugs and new features of an official prerelease. There is no guarantee that the nightly build is available or will work. Now I define all the steps of creating the project.

Step 1

First we create the Web API project as in the following:

Step 2

Now we install the client package.

When the Web API Test Client is installed, the following files will be added to your application:

Step 3

Now open the "TestClientReference.cshtml" file. This file exists in the Solution Explorer: "Areas\HelpPage\Views\DisplayTemplates\TestClientReferences.cshtml".

And write this code.

  1. @using System.Text.RegularExpressions
  2. <script src="~/Scripts/jquery-1.8.2.js"></script>
  3. <script src="~/Scripts/knockoutjs%202.1.0.js"></script>
  4. <script src="~/Scripts/jquery-ui-1.10.3.js"></script>
  5. <link href="~/Content/themes/base/jquery.ui.all.css" rel="stylesheet" />
  6. <link href="~/Areas/HelpPage/TestClient.css" rel="stylesheet" />
  7. @* Automatically grabs the installed version of JQuery/JQueryUI/KnockoutJS *@
  8. @{var filePattern = @"(jquery-[0-9]+.[0-9]+.[0-9]+.js|jquery-ui-[0-9]+.[0-9]+.[0-9]+.js|knockout-[0-9]+.[0-9]+.[0-9]+.js)";}
  9. @foreach (var item in Directory.GetFiles(Server.MapPath(@"~/Scripts")).Where(f => Regex.IsMatch(f, filePattern)))
  10. {
  11. <script src="~/Scripts/@Path.GetFileName(item)"></script>
  12. }
  13. <script src="~/Scripts/WebApiTestClient.js" defer="defer"></script>

In this code we use some JavaScripts files that exist in the "Script" folder. We can drag and drop these files from the Script folder. These files are:

Step 4

Now open the "Api.cshtml" file. This file exists in Solution Explorer: "Areas\HelpPage\Views\Help\Display". And write this code:

  1. @using System.Web.Http
  2. @using cors.Areas.HelpPage.Models
  3. @model HelpPageApiModel
  4. @{
  5. var description = Model.ApiDescription;
  6. ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath;
  7. }
  8. <div id="body">
  9. <section class="featured">
  10. <div class="content-wrapper">
  11. <p>
  12. @Html.ActionLink("Help Page Home", "Index")
  13. </p>
  14. </div>
  15. </section>
  16. <section class="content-wrapper main-content clear-fix">
  17. @Html.DisplayFor(m => Model)
  18. </section>
  19. </div>
  20. @Html.DisplayForModel("TestClientDialogs")
  21. @section Scripts {
  22. <link type="text/css" href="~/Areas/HelpPage/HelpPage.css" rel="stylesheet" />
  23. @Html.DisplayForModel("TestClientReferences")
  24. }

Step 5

Now we add the "Nightly Build" to this project.

Step 6

Use the Nightly Builds as in the following:

Step 7

Now install the MicroSoft.AspNet.WebApi.Cors from the nightly builds.

corsupdate.jpg

Step 8

Execute the application.

up11.jpg

Click on "API".

Then click on "GET/api/values ".

up2.jpg


Click on "Test API".

up3.jpg

Now click on the "Send" button. The output looks like this:

up4.jpg