当前上下文中不存在名称“ConfigureAuth”

当我试图运行我的页面时,我收到错误说,

当前上下文中不存在名称“ConfigureAuth”

在我的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.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); } 

我有类似的问题,为了解决我在Startup.Auth.cs文件中从名称空间中删除.App_Start的问题。 之后,我能够看到参考。

它是:

  [assembly: **OwinStartup**(typeof(Project-Name.Startup))] namespace project-name { public partial class Startup { public void **Configuration**(IAppBuilder app) { 

要么

  [assembly: **OwinStartupAttribute**(typeof(Project-Name.Startup))] namespace project-name { public partial class Startup { public void **ConfigureAuth**(IAppBuilder app) { 

将OwinStartupAttribute重命名为OwinStartup或配置为ConfigureAuth

请注意,两个部分类( Startup.Auth.csStartup.cs )应该位于同一个名称空间中,该名称空间是项目的根目录,只需将Startup.Auth.cs的名称空间更改为Startup的同一名称空间即可。 的.cs

确保最初创建项目时名称中没有空格。 例如,我的应用程序被称为“DevOps Test”,当我运行它时,它给了我错误。 我将其重新创建为“DevopsTest”并且不再存在这些问题