ASP.NET WEB API启动类

时间:2015-03-10 01:00:47

标签: c# asp.net-web-api dependency-injection owin

我目前正在使用Ninject进行依赖注入。这个项目基于ASP.NET WEB APP 2.每当我运行我的应用程序时,我在startup.cs类中得到错误{app null}。我有一个未处理的类型' System.StackOverflowException'发生在Phase2_Group2_selucmps383_sp15_p2_g2.dll

[assembly: OwinStartup(typeof(Phase2_Group2_selucmps383_sp15_p2_g2.Startup))]
    namespace Phase2_Group2_selucmps383_sp15_p2_g2
    {
        public partial class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                Configuration(app);
            }
        }
    }

App_Start startup.cs类是:

namespace Phase2_Group2_selucmps383_sp15_p2_g2.App_Start
{
    public partial class Startup
    {
        public static string PublicClientId { get; private set; }

        public static Func<UserManager<IdentityUser>> UserManagerFactory { get; set; }

        public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
        static Startup()
        {

            PublicClientId = "self";

            UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>());

            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/Token"),
                Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
                AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                AllowInsecureHttp = true
            };

        }

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();
            config.DependencyResolver = new NinjectResolver(NinjectWebCommon.CreateKernel());

            config.Routes.MapHttpRoute("default", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            app.UseWebApi(config);



            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            app.UseOAuthBearerTokens(OAuthOptions);
            Configuration(app);
        }
    }
}

这是什么问题?有帮助吗?如果需要,很乐意发布任何其他内容。

1 个答案:

答案 0 :(得分:0)

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigAuth(app);
    }
}

也在另一个startup.cs文件中,将方法名称更改为与上面相同。