Using AJAX object with ASP.NET WEB API

Index

Attached Files

The following files have been attached to this tutorial:

.zip

c2-and-aspnet-template-project-for-vs-2013.zip

Download now 22.16 MB

Stats

2,856 visits, 8,485 views

Translations

This tutorial hasn't been translated.

Tools

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 2 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!

  • 0 Comments

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