加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在MVC 4中使用ASP.Net Identity

发布时间:2020-12-15 23:24:28 所属栏目:asp.Net 来源:网络整理
导读:在即将到来的ASP.net: http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx版本中,我一直在阅读有关新的auth的内容 我在Visual Studio 2012中创建了一个新的ASP.net MVC 4项
在即将到来的ASP.net: http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx版本中,我一直在阅读有关新的auth的内容

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

我正在阅读代码,并试图围绕这个新的API.但与此同时,要走什么步骤呢?

解决方法

应该是可以的,首先你基本上要安装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

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

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读