名称configureauth不存在。

4
我正在尝试这个教程:http://httpjunkie.com/2013/311/adding-mvc-5-identity-to-an-existing-project/,但是出现了错误 Error 5 The name 'ConfigureAuth' does not exist in the current context
这是我的startup.cs类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Microsoft.Owin;
using Owin;

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



      }
    }

这是Startup.Auth.cs文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;

using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
namespace TicketSystem.App_Start
{
    public partial class Startup
    {

        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            // clientId: "",
            // clientSecret: "");

            //app.UseTwitterAuthentication(
            // consumerKey: "",
            // consumerSecret: "");

            //app.UseFacebookAuthentication(
            // appId: "",
            // appSecret: "");

            //app.UseGoogleAuthentication();
        }
    }
}
1个回答

9
您在两个文件中使用了不同的命名空间:namespace TicketSystem.App_Startnamespace TicketSystem。请确保它们是相同的。或者,在您的startup.cs类中添加using语句:using TicketSystem.App_Start
如果您检查示例,您会看到这两个文件都使用了相同的命名空间(namespace MVC5FullApp)。

我遇到了同样的问题。我尝试使用using语句,但没有成功。我不明白的是,如果两个部分Startup类的命名空间在开始时使用模板创建,那么为什么会出现错误?它使用解决方案的名称作为Startup.cs部分的名称,使用项目的名称作为Startup.Auth.cs部分的名称。 - Edward

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