gpt4 book ai didi

c# - ASP.NET WEB API 启动类

转载 作者:太空宇宙 更新时间:2023-11-03 15:44:06 25 4
gpt4 key购买 nike

我目前正在使用 Ninject 进行依赖注入(inject)。该项目基于 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);
}
}
}

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

最佳答案

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

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

关于c# - ASP.NET WEB API 启动类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28954498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com