13

我一直在阅读即将发布的 ASP.net 版本中的新身份验证内容:http: //blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership -system-for-asp-net-applications.aspx

我正在 Visual Studio 2012 中创建一个新的 ASP.net MVC 4 项目,如果可以的话,我想使用新的身份验证位。这可能吗?

我正在阅读代码并试图围绕这个新 API 进行思考。但与此同时,要采取哪些步骤?

4

1 回答 1

20

它应该是可行的,首先你基本上要安装3个包:

Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.EntityFramework
Microsoft.AspNet.Identity.Owin

然后,您还需要拉入相关的 Owin 包:

Owin
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Host.SystemWeb

然后你需要用这样的东西连接 Owin:

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(WebApplication19.Startup))]
namespace WebApplication19
{
    public partial class Startup
    {
        public void Configuration(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);
        }
    }
}

您还必须删除/关闭应用程序中所有旧的会员资格/表单身份验证,并切换到使用新的身份 API。

于 2013-10-09T22:29:56.070 回答