在MVC 4使用ASP.Net身份 [英] Using ASP.Net Identity in MVC 4

查看:102
本文介绍了在MVC 4使用ASP.Net身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关在ASP.net的未来版本的新AUTH的东西:<一href=\"http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx\">http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx

I've been reading about the new auth stuff in the upcoming versions of 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项目,我想,如果我可以使用新的身份验证位。这可能吗?

I'm creating a new ASP.net MVC 4 project in visual studio 2012 and I'd like to use the new auth bits if I can. Is this possible?

我在读code,并试图环绕这个新的API我的头。但在此期间,哪些步骤都参与得走?

I'm reading code and trying to wrap my head around this new API. But in the meantime, what steps are involved to get going?

推荐答案

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

It should be doable, first you basically want to install the 3 packages:

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

您会那么需要在相关Owin包拉,以及:

You would then need to pull in the associated Owin packages as well:

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

和你再需要联播Owin像这样的东西:

And you would then need to hookup Owin with something like this:

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。

You will also have to remove/turn off all of the old membership/forms auth in your app, and switch to using the new identity APIs.

这篇关于在MVC 4使用ASP.Net身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆