【问题标题】:The name 'ConfigureAuth' does not exist名称“ConfigureAuth”不存在
【发布时间】:2016-08-31 18:10:42
【问题描述】:

VS 2015 + 所有更新。 添加了一个带有身份验证的 ASP .Net 项目(身份) 目标 - 将项目分层。

图层:

DataAccess(所有数据库表、模型等)

业务逻辑(CRUD 操作)

Web 类库(所以我不需要绑定 DA 和 BL 我添加了一个额外的层来执行此操作)

ASP .Net Web 应用程序

  1. 将模型文件夹移动到 DA。
  2. 将 IdentityConfig.cs 移到 DA 的根目录中。
  3. 添加 DA 所需的所有引用,相应地更改命名空间。项目构建成功。
  4. 将 Controller 文件夹移动到 BL 中。
  5. 添加 BL 所需的所有引用,相应地更改命名空间。项目构建成功。
  6. 将 BundleConfig、FilterConfig、RouteConfig 和 Startup.Auth 移动到 Web 类库的根目录。
  7. 添加网络库所需的所有引用。项目构建成功。
  8. 在 Web 应用程序中,我更改了启动和

类和项目中的代码:

using Microsoft.Owin;
using Owin;
using Company.Web;

[assembly: OwinStartupAttribute(typeof(Startup))]
namespace Company.Web
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
             ConfigureAuth(app);
        }
    }
}

Startup.Auth中的代码

namespace Company.Web
{
    public partial class Startup
    {
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request

我得到了错误

抑制状态错误 CS0103 当前上下文 WebApplication1 中不存在名称“ConfigureAuth”

我在“启动”上写了一个友好的消息:

[程序集:OwinStartupAttribute(typeof(Startup))]

'....WebApplication1\Startup.cs' 中的类型 'Startup' 与 'Company.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 中导入的类型 'Startup' 冲突'。使用 '....WebApplication1\Startup.cs' 中定义的类型。

错误

CS0103 当前上下文 WebApplication1 ....WebApplication1\Startup.cs 中不存在名称“ConfigureAuth”

所以我四处研究并看到了一些链接,例如

the name configureauth does not exist The name 'ConfigureAuth' does not exist in the current contex ASP.NET MVC OWIN and SignalR - two Startup.cs files

但是如果我构建这个项目的方式不正确或者我遗漏了一些明显的东西,我就无法解决?

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc asp.net-identity


    【解决方案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);
    }
    

    【讨论】:

    • ConfigureAuth 方法与您发布的相同。问题是我必须在同一个项目中拥有 Startup.cs - 在本例中是 company.web 项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 1970-01-01
    • 2021-02-18
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    相关资源
    最近更新 更多