1

I have an existing MVC project which has a knockout front end and a WebAPI back end.

Due to a change in requirements I had to remove all the back end files from the project, leaving only the front end files.

Now I need to a WebAPI controller back into the project.

In order to configure the WebAPI I need to find an entry point into the C# code to trigger the configuration methods.

My understanding is that if the project has a Global.asax file, the Application_Start() will automatically be fired on start up. And also if I have a startup.cs file with an owinStartup property, this will also be triggered by default.

So I copied both these files from another project and edited as required, but neither files are being triggered on startup.

I assume I am missing some kind of configuration, but am not sure what?

Here is my startup.cs file:

using System.Web.Http;
using Microsoft.Owin;
using Newtonsoft.Json;
using Owin;

[assembly: OwinStartup(typeof(ClearviewLocal_ONFrontEnd_Rest.Startup))]
namespace ClearviewLocal_ONFrontEnd_Rest
{
    /// <summary>
    /// Application startup
    /// </summary>
    public class Startup
    {
        /// <summary>
        /// Configure app
        /// </summary>
        /// <param name="app">Owin AppBuilder</param>
        public void Configuration(IAppBuilder app)
        {         
            var config = new HttpConfiguration();         //breakpoint here that is not being hit
        }
    }
}

and here is the Global.asax file:

using System;
using System.Web;
using System.Web.Http;

namespace ClearviewLocal_ONFrontEnd_Rest
{
    /// <summary>
    /// 
    /// </summary>
    public class WebApiApplication : HttpApplication
    {
        /// <summary>
        /// 
        /// </summary>
        protected void Application_Start()
        {
            var config = new HttpConfiguration(); //Breakpoint here            
        }
    }
}

I have looked at the answer to this question: OwinStartup not Starting ... Why? but this code was never in the Web.Config

Also, I have not removed any references from the project

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Alex
  • 3,730
  • 9
  • 43
  • 94
  • Out of curiosity, what happened for you to have to get rid of all the 'back end' files? –  May 11 '18 at 08:11
  • @JᴀʏMᴇᴇ The WebAPI calls got moved out into another project as they were required by other projects aswell – Alex May 11 '18 at 08:12

1 Answers1

1

The accepted answer to this question OwinStartup not firing seems to have solved my issue:

" Make sure you have installed Microsoft.Owin.Host.SystemWeb package in the project. This package is needed for startup detection in IIS hosted applications. "

Alex
  • 3,730
  • 9
  • 43
  • 94