Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web API Routing Not working in Web Site App.

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
0
0
AU
I have developed an web application in Visual Studio 2013 which uses the development server that comes with VS.
I now want to port it to a Website to use IIS running on my PC.
I have had a thousand challenges to date, not the least of which is the Global.asax file which registers all the web API stuff.
In order for it to compile, I had to separate out the code behind to a class called 'Global' in the 'App_Code' folder and have Global.asax inherit from Global.
It all compiles happily now.

I have also put all my Web API controllers under the app_code folder as per various recommendations.

However, in debug mode at least, Application_Start never seems to run, so I can't be sure my web api stuff is being initialised.
in IE under developer tools, the first call to a web api controller falls over with a 404, and it think its a text/html call, not application/json. The call is a $.getJSON method.

Any help much appreciated.

This is how the Global.asax file look:
Code:
<%@ Application Codebehind="Global.asax.cs" inherits="Global" Language="C#" %>
This is how the Global.cs file looks.
Code:
public class Global : System.Web.HttpApplication

{	
		 public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            
            //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<GNC_CorpContext>());
            // LearnNow version with context added.
            Database.SetInitializer<Test_CACS_Data.Models.Test_CACS_DataContext>(new DropCreateDatabaseIfModelChanges<Test_CACS_DataContext>());
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

There has to be a pony in this pile of s*%t somewhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top