configureauth这个名称不存在

时间:2015-05-06 10:30:34

标签: c# model-view-controller owin

我正在尝试本教程 http://httpjunkie.com/2013/311/adding-mvc-5-identity-to-an-existing-project/ 但是给我看错了 错误5当前上下文中不存在名称“ConfigureAuth”  这是我的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 个答案:

答案 0 :(得分:9)

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