类型“Startup”已经定义了一个名为“Configuration”的成员,其参数类型相同。

5

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

然而,它无法编译并出现以下错误:

Image

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

2个回答

9

虽然简单,但很难找到。问题在于另一个开发者在项目结构的不同文件夹中创建了具有相同签名的startup.cs文件。我会在这里留下证据,因为这可能对其他开发者有用。


在我的情况下,同一项目中的一个文件夹里存在另一个启动文件。请注意准确性。 - Shelly

0
你可以在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;
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接