22
votes

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());          
        }
    }
}
2
Could you submit MyStartupClass class?Sam FarajpourGhamari
What parts of my class would be relevant? It is quite big containing a lot of stuff that is unrelated. It's worth noting that my startup class is derived from another startup class residing in a class library.Sjoerd222888
Remove irrelevant parts I just want to see your class structure and outline.Sam FarajpourGhamari
And which one you registered on web.config?Sam FarajpourGhamari

2 Answers

37
votes

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.

0
votes

Sometimes if you rename your project name then also you can get this error. Please make sure to rename your assembly info & please check your project properties also. Right Click on your Project => Go To Properties => Verify your assembly name and project name.

For me this solved my issue with OWIN library.

Project Properties Assembly Name Change