【问题标题】:The name 'ConfigureAuth' does not exist in the current contex当前上下文中不存在名称“ConfigureAuth”
【发布时间】:2015-02-02 04:47:09
【问题描述】:

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

当前上下文中不存在名称“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);
        }
     }
}

【问题讨论】:

  • 你在哪里得到错误?在 Build 上,在 IIS 中运行,在 IIS Express 中运行,在 Cassini 中运行,通过 mod-mono 在 linux 上运行....??

标签: c# asp.net-mvc asp.net-mvc-4 razor owin


【解决方案1】:

如果您使用默认的 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);
}

【讨论】:

  • 对我来说是命名空间问题,检查this,希望对某人有所帮助。
  • 我遇到了同样的问题。我确实对命名空间差异使用了 using 语句,但没有成功。我不明白的是,如果两个部分 Startup 类的命名空间是在开始时使用模板创建的,那么为什么会出现错误?它使用 Startup.cs 部分的解决方案名称和 Startup.Auth.cs 部分的项目名称
  • 您能列出这里使用的命名空间吗?我找不到ApplicationUserManagerOAuthServerOptions 等。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    是:

        [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

    【讨论】:

      【解决方案4】:

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

      的相同命名空间

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

          命名空间 PAYOnline.App_Start

          仅删除 App_Start 命名空间 PAYOnline => 做得很好

          【讨论】:

            猜你喜欢
            • 2016-08-31
            • 1970-01-01
            • 2013-10-02
            • 2014-04-22
            • 2017-06-17
            • 2015-09-11
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多