2012-08-27 23 views
0

我昨天安装了Visual Studio 2012(RTM,通过mytt DreamSpark帐户),并创建了一个演示MVC站点(使用.NET 4.0,因为我希望它在Azure上受支持)。ASP.NET 4 Membeship架构已更改

我已经开始调查该项目,除了使用外部服务(Facebook,Twitter,Windows Live和Google)的内置选项外,我发现整个会员模式已被更改:

新结构包含4个表(UserProfile是第一个代码接近实体框架表)。 请注意,虽然表前缀是“webpages_”,但它是一个适当的MVC 4站点。

我已经打开了AccountModels.cs文件,发现它已被更改过:

using System; 
using System.Collections.Generic; 
using System.ComponentModel.DataAnnotations; 
using System.ComponentModel.DataAnnotations.Schema; 
using System.Data.Entity; 
using System.Globalization; 
using System.Web.Mvc; 
using System.Web.Security; 

namespace MyGuestbook.Models 
{ 
    public class UsersContext : DbContext 
    { 
     public UsersContext() 
      : base("DefaultConnection") 
     { 
     } 

     public DbSet<UserProfile> UserProfiles { get; set; } 
    } 

    [Table("UserProfile")] 
    public class UserProfile 
    { 
     [Key] 
     [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] 
     public int UserId { get; set; } 
     public string UserName { get; set; } 
    } 

    public class RegisterExternalLoginModel 
    { 
     [Required] 
     [Display(Name = "User name")] 
     public string UserName { get; set; } 

     public string ExternalLoginData { get; set; } 
    } 

    public class LocalPasswordModel 
    { 
     [Required] 
     [DataType(DataType.Password)] 
     [Display(Name = "Current password")] 
     public string OldPassword { get; set; } 

     [Required] 
     [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] 
     [DataType(DataType.Password)] 
     [Display(Name = "New password")] 
     public string NewPassword { get; set; } 

     [DataType(DataType.Password)] 
     [Display(Name = "Confirm new password")] 
     [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] 
     public string ConfirmPassword { get; set; } 
    } 

    public class LoginModel 
    { 
     [Required] 
     [Display(Name = "User name")] 
     public string UserName { get; set; } 

     [Required] 
     [DataType(DataType.Password)] 
     [Display(Name = "Password")] 
     public string Password { get; set; } 

     [Display(Name = "Remember me?")] 
     public bool RememberMe { get; set; } 
    } 

    public class RegisterModel 
    { 
     [Required] 
     [Display(Name = "User name")] 
     public string UserName { get; set; } 

     [Required] 
     [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] 
     [DataType(DataType.Password)] 
     [Display(Name = "Password")] 
     public string Password { get; set; } 

     [DataType(DataType.Password)] 
     [Display(Name = "Confirm password")] 
     [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 
     public string ConfirmPassword { get; set; } 
    } 

    public class ExternalLogin 
    { 
     public string Provider { get; set; } 
     public string ProviderDisplayName { get; set; } 
     public string ProviderUserId { get; set; } 
    } 
} 

所以我想问: - 这是否新的用户结构(即由asp_regsql产生.exe)或者这是一个特定于模板的结构? - 有人有关于新结构的文档以及如何与其结合? - 有人知道如何将旧结构的“旧”项目(例如MVC 3项目)迁移到新结构?

谢谢! :)

回答

1

我发现了一些文章,回答我的问题。

编辑: 为什么突然改变: 的变化已经作出,因为微软已经更改了默认的ASP.NET MVC 4模板。 默认帐户管理的标准“Internet应用程序”模板已更改,现在使用WebMatrix 2助手。 AccountController已被完全重写,以便使用SimpleMembership类来支持第三方集成,并使我们能够使用实体框架代码优先方法。

使用老的成员资格提供 只要我读过的,因为使用ExtendedMembershipProviderSimpleMembership类,你可以不使用默认的通用供应商,并且必须使用内置的提供商或创建ExtendedMembershipProvider定义提供。

更多信息可以在这里找到: Implementing membership providers using the new ASP.NET WebForms and ASP.NET MVC 4 template

干杯!

+0

请在此处总结或引用关键位。链接腐烂发生,渲染链接只回答完全无用。 –

+0

上面的链接总结了传统ASP.NET方案与ASP.NET MVC 4使用的新方案和项目模板之间的区别。我的问题的答案是文章内容......没有具体的答案整个问题。 –