gpt4 book ai didi

c# - 当前上下文中不存在名称 'ConfigureAuth'

转载 作者:太空狗 更新时间:2023-10-29 18:11:56 25 4
gpt4 key购买 nike

当我尝试运行我的页面时出现错误,

The name 'ConfigureAuth' does not exist in the current context

在我的 Stratup 类中。我确定所有 AspNet Identity 库都已安装。接下来我需要做什么来尝试解决这个问题?

using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(project_name.Startup))]
namespace project_name
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}

最佳答案

如果您使用默认的 Visual Studio 项目模板,则可以在分部类 Startup.Auth.cs 中找到 ConfigureAuth 方法。因此,请确保在修改项目结构时没有破坏任何东西。

这是 ConfigureAuth 方法的一个例子:

// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context and user manager to use a single instance per request
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/api/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};

// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}

关于c# - 当前上下文中不存在名称 'ConfigureAuth',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28271265/

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