【问题标题】:Type 'Startup' already defines a member called 'Configuration' with the same parameter types类型“启动”已经定义了一个名为“配置”的成员,具有相同的参数类型
【发布时间】:2019-03-07 01:19:51
【问题描述】:

我的 startup.cs 上有这个

using Microsoft.Owin;
using Owin;

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

我有这个 Startup.Auth.cs

using System;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;

namespace xx.yy
{
    public static class xxAuthentication
    {
        public const String ApplicationCookie = "xxAuthenticationType";
    }

    public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = xxAuthentication.ApplicationCookie,
                LoginPath = new PathString("/Login"),
                Provider = new CookieAuthenticationProvider(),
                CookieName = "ComisionesCookie",
                CookieHttpOnly = true,
                ExpireTimeSpan = TimeSpan.FromHours(12), // adjust to your needs
            });
        }
    }
}

但是编译时不会出现这个错误:

我使用此页面中的代码 http://tech.trailmax.info/2016/03/using-owin-and-active-directory-to-authenticate-users-in-asp-net-mvc-5-application/

【问题讨论】:

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


    【解决方案1】:

    很容易,但很难找到,问题是另一个开发人员在项目结构的不同文件夹中创建了一个具有相同签名的 startup.cs 文件。将在此处留下证据,因为它可能对其他开发人员有用

    【讨论】:

    • 没错,在我的情况下,同一个项目中的另一个启动文件存在于一个文件夹中
    【解决方案2】:

    您可能必须像这样在 Startup 类中创建构造函数成员:

    public class Startup {
    
        public Startup(IConfiguration _configuration){
            this._configuration = _configuration;
        }
    
        private IConfiguration _configuration{ 
            get; 
        }
    
        public Startup(IConfiguration configuration){
            // Expose the injected instance locally so we populate our settings instance
            _configuration = configuration;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-15
      • 1970-01-01
      • 2014-03-20
      • 2020-06-17
      • 2022-12-11
      • 1970-01-01
      相关资源
      最近更新 更多