【问题标题】:the name configureauth does not exist名称 configureauth 不存在
【发布时间】:2015-05-06 18:44:37
【问题描述】:

我正在尝试这个教程 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();
        }
    }
}

【问题讨论】:

    标签: c# model-view-controller owin


    【解决方案1】:

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

    【讨论】:

    • 我遇到了同样的问题。我确实使用了 using 语句没有成功。我不明白的是,如果两个部分 Startup 类的命名空间是在开始时使用模板创建的,那么为什么会出现错误?它使用 Startup.cs 部分的解决方案名称和 Startup.Auth.cs 部分的项目名称
    猜你喜欢
    • 2016-08-31
    • 1970-01-01
    • 2016-11-06
    • 1970-01-01
    • 2021-02-18
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    相关资源
    最近更新 更多