Adding Startup class to Web Api service RRS feed

  • Question

  • User-1763141223 posted

    I created ODATA Web Api Service as described in http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint . Now I need my service to access ASP.NET Membership database, I looked how it was done in standard ASP.NET VS application - seems like Owin can help  so  now need to enable my web service with Owin. To add owin I first added the class

    [assembly: OwinStartupAttribute(typeof(WebService.Startup))]
    namespace WebService
        public class Startup
            public void Configuration(IAppBuilder app)
                HttpConfiguration config = new HttpConfiguration();

    but its method Configuration is never called. I suspected that it could have something to do to the Global.asax with this content:

    public class WebApiApplication : System.Web.HttpApplication
            protected void Application_Start()
            public override void Init()

    So I commented out the call to


    and now I am experiencing:

    HTTP Error 500.0 - Internal Server Error without any specific details.

    My Startup.Configuration is still not called so seems like that call in the line above is mandatory but I was hoping to substitute it with identical call from inside Startup.Configuration.

    Can you tell me the right way to enable Owin (I assume Startup.Configuration should be called) in my existing web service?

    Wednesday, September 16, 2015 3:00 AM


  • User1104055534 posted

    Hi AverageAsker,

    Thanks for your post here.

    From your code snippet, it seems like there is a litter different as my locally api project. Could you go ahead to check the following line, please check with OwinStartupAttribute?

    • [assemblyOwinStartup(typeof(iService.Startup))]

    Also I noticed that you have initiated an object instance of HttpConfiguration, but there is nothing in this object. Maybe you want to initialize this HttpConfiguration object with following example:

                // Web API configuration and services
                // Configure Web API to use only bearer token authentication.
                config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
                // Web API routes
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 18, 2015 6:19 AM