Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Owin provide startup class in web.config (no automatic startup discovery)

Tags:

I try to do the following in my web.config:

<appSettings>    <add key="owin:AutomaticAppStartup" value="false" />    <add key="owin:appStartup" value="MyNamespace.MyStartupClass" /> </appSettings> 

If I understand this documentation correctly automatic startup detection should be disabled. So I do not require a startup attribute.

Unfortunately it looks like OWIN does not start. (I see this because I get the error: HTTP Error 403.14 - Forbidden. I use a controller to handle requests to the index file.)

if I use <add key="owin:AutomaticAppStartup" value="true" /> and add the startup attribute [assembly: OwinStartup(typeof(MyStartupClass))] then the application does startup as expected.

So the question is why? What can I do to resolve the issue?

I am using OWIN 3.0.0.0

Update:

This is how my startup class looks like (minified version with relevant parts):

using System.Web.Http; using Microsoft.AspNet.SignalR; using Microsoft.Owin; using Owin; using MyOtherNamespace;  namespace MyNamespace {     public class MyOnlineStartup : MyOtherStartup     {         public new void Configuration(IAppBuilder app)         {             base.Configuration(app); //Call base method! This is important because otherwise ther serilization will not be correct             HttpConfiguration config = CreateRouting();             config.Routes.MapHttpRoute("exampleAppNone", "", new { controller = "MyIndex" }, null, null);             config.Routes.MapHttpRoute("exampleAppIndex", "index.html", new { controller = "MyIndex" }, null, null);             app.UseWebApi(config); // Use the WebAPI technology.         }     } } 

it derives from

using System.Linq; using System.Web.Http; using Microsoft.AspNet.SignalR; using Newtonsoft.Json; using Owin;  namespace MyOtherNamespace {     public class MyOtherStartup     {         protected static HttpConfiguration CreateMyRouting()         {             HttpConfiguration config = new HttpConfiguration();             config.Routes.MapHttpRoute(                 "myIndex",                 "my/",                 new                 {                     controller = "MyIndex"                 },                 null,                 null                 );             config.Routes.MapHttpRoute(                 "myIndex2",                 "my/index.html",                 new                 {                     controller = "MyIndex"                 },                 null,                 null                 );             var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");             config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);             config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto             return config;         }          public void Configuration(IAppBuilder app)         {             JsonSerializer serializer = Serialization.ClientJsonSerializer();             serializer.ContractResolver = new MySerializationContractResolver(false);             GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer);             app.MapSignalR("/" + MyRequestHandler.MySignalRPath, new HubConfiguration());                   }     } } 
like image 392
Sjoerd222888 Avatar asked Aug 11 '15 12:08

Sjoerd222888


People also ask

How do I disable OWIN startup discovery in web config?

To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web. config. To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.

How do I add OWIN startup classes?

Add an OWIN startup class. In Visual Studio 2017 right-click the project and select Add Class. - In the Add New Item dialog box, enter OWIN in the search field, and change the name to Startup. cs, and then select Add.


1 Answers

Simply remove this line of code in web.config file:

<add key="owin:AutomaticAppStartup" value="false" /> 

Your web.config file now must look like this:

<appSettings>     <add key="owin:appStartup" value="MyNamespace.MyStartupClass" /> </appSettings>   

By adding just owin:appStartup key you don't need startup attribute.

like image 78
Sam FarajpourGhamari Avatar answered Sep 21 '22 06:09

Sam FarajpourGhamari