2016-04-25 10 views
0

Ich entwickle eine Website in MVC 5 mit Code zuerst Migration. Ich möchte die benutzerdefinierten Attribute in der Standardidentität hinzufügen, um die Benutzerdaten zu aktualisieren, aber ich konnte die AspNetUsers-Tabelle nicht aktualisieren, obwohl ich auch die Migrations- und Aktualisierungsdatenbank hinzugefügt habe, aber das Ergebnis ist das gleiche. Mein Code ist in applicationUser Ich habe drei weitere Eigenschaften hinzufügen.Wie aktualisiert man den Identity User?

public class ApplicationUser : IdentityUser 
{ 
    public string Name { get; set; } 
    public string MobileNo { get; set; } 
    public string Address { get; set; } 

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) 
    { 


     // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 
     // Add custom user claims here 
     return userIdentity; 
    } 

} 

dann aktualisiere ich RegisterViewModel

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

    [Required] 
    [EmailAddress] 
    [Display(Name = "Email")] 
    public string Email { 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; } 

    [Required] 
    [Display(Name = "Mobile Number")] 
    public string MobileNo { get; set; } 

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

und Register View ist

<h4>Create a new account.</h4> 
<hr /> 
@Html.ValidationSummary("", new { @class = "text-danger" }) 

<div class="form-group"> 
    @Html.LabelFor(m => m.Name, new { @class = "col-md-2 control-label" }) 
    <div class="col-md-10"> 
     @Html.TextBoxFor(m => m.Name, new { @class = "form-control" }) 
    </div> 
</div> 

<div class="form-group"> 
    @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" }) 
    <div class="col-md-10"> 
     @Html.TextBoxFor(m => m.Email, new { @class = "form-control" }) 
    </div> 
</div> 
<div class="form-group"> 
    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" }) 
    <div class="col-md-10"> 
     @Html.PasswordFor(m => m.Password, new { @class = "form-control" }) 
    </div> 
</div> 
<div class="form-group"> 
    @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" }) 
    <div class="col-md-10"> 
     @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" }) 
    </div> 
</div> 

<div class="form-group"> 
    @Html.LabelFor(m => m.MobileNo, new { @class = "col-md-2 control-label" }) 
    <div class="col-md-10"> 
     @Html.TextBoxFor(m => m.MobileNo, new { @class = "form-control" }) 
    </div> 
</div> 
<div class="form-group"> 
    @Html.LabelFor(m => m.Address, new { @class = "col-md-2 control-label" }) 
    <div class="col-md-10"> 
     @Html.TextBoxFor(m => m.Address, new { @class = "form-control" }) 
    </div> 
</div> 
<div class="form-group"> 
    <div class="col-md-offset-2 col-md-10"> 
     <input type="submit" class="btn btn-default" value="Register" /> 
    </div> 
</div> 

nach der Migration und Update-Datenbank in der Konsole Manager Hinzufügen Ich bin nicht in der Lage, die Spalten in AspNetUsers Tabelle zu erstellen und Wenn ich das -Verbose-Flag verwende, dann war die Fehlermeldung "Das Objekt" AspNetUsers "kann nicht gefunden werden, weil es nicht existiert oder Sie keine Erlaubnis haben Ionen. " Ich kann nicht verstehen, wie das Problem zu beheben ist. Bitte sagen Sie mir, wie ich mit diesem Problem umgehen soll. Danke

Antwort

1

Überprüfen Sie, ob Sie tatsächlich eine Verbindung zu Ihrer Datenbank herstellen können, da eine fehlgeschlagene Verbindung möglicherweise die Aktualisierung der Datenbanktabelle verhindert. Ich verwende diese Verbindungszeichenfolge in meinem Code:

<connectionStrings> <add name="CONNECTIONSTRING_NAME" connectionString="Data Source(local); Initial Catalog=YOUR_DATABASE_NAME;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

Verwandte Themen