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

kez*_*kez 9 c# asp.net-mvc razor asp.net-mvc-4 owin

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

当前上下文中不存在名称"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);
        }
     }
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*diy 8

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

这是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);
}
Run Code Online (Sandbox Code Playgroud)

  • 对我来说这是命名空间问题,请查看[this](http://stackoverflow.com/a/30074236/2218697),希望能帮助某人. (5认同)

小智 8

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