【发布时间】:2015-05-11 08:19:08
【问题描述】:
我目前正在使用 Ninject 进行依赖注入。该项目基于 ASP.NET WEB APP 2。每当我运行我的应用程序时,我都会在 startup.cs 类中收到错误 {app null}。我在 Phase2_Group2_selucmps383_sp15_p2_g2.dll 中发生了“System.StackOverflowException”类型的未处理异常
[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);
}
}
}
这里有什么问题?有什么帮助吗?如果需要,很乐意发布其他任何内容。
【问题讨论】:
-
你有声明
[assembly: OwinStartup(typeof(Bla))]吗?见asp.net/aspnet/overview/owin-and-katana/… -
@abatishchev:我有。
-
好的,你有它。它被调用了吗?您在哪一行收到错误消息?
-
@abatishchev,每当我运行它时,我都会将 app 的值设为 null。在第一个启动类中。
标签: c# asp.net-web-api dependency-injection owin