Using AJAX object with ASP.NET WEB API

2

Index

Stats

12,491 visits, 29,583 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 8 Dec, 2014. Last updated 12 Oct, 2020

Getting things ready... step 4 of 4

Before we start we must make some adjusts, it will make things easier in the next steps ;)

Tip: You can download a template project at Tutorial Downloads with all code and packages you'll need to start coding ;) If you like to download it, jump to Step 6.

Install WebAPI2Construct from NuGet Package Manager

WebAPI2Construct simplifies the integration of ASP.NET Web API with Construct game engine.

1. Right click the project's name

2. Click Manage NuGet Packages...

3. Select Online at the left side of the screen and type "WebAPI2Construct" in the Search field at the right side of the screen

4. Select WebAPI2Construct and click Install

Accepting HTTP GET requests

1. Open the Global.asax file in the project root folder

2. Add this code inside the Application_Start method:

    // Register global filter
    // Accept GET requests to all controller and all actions in the project
    GlobalFilters.Filters.Add(new System.Web.Http.HttpGetAttribute());

Your complete Global.asax file will looks like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Http;
    using System.Web.Mvc;
    using System.Web.Optimization;
    using System.Web.Routing;

    namespace MyGameName
    {
        public class WebApiApplication : System.Web.HttpApplication
        {
            protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();
                GlobalConfiguration.Configure(WebApiConfig.Register);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);

                // Register global filter
                // Accept GET requests in all Controllers and all Actions in this project
                GlobalFilters.Filters.Add(new System.Web.Http.HttpGetAttribute());

            }
        }
    }

Click Save in the toolbar or press Ctrl + Shift + S to save all.

Before continue...

Now, try to build the project by clicking BUID > Build Solution. If it fails, go back and revise your code.

Something went wrong?

Tip: You can download a template project at Tutorial Downloads with all code and packages you'll need to start coding ;) If you like to download it, jump to Step 6.

Done! We are ready to go!

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!