我有一個使用ASP.NET成員資格提供程序的基本應用程序。默認情況下,您可以使用幾個字段,如用戶名,密碼,記住我。如何使用ASP.Net成員資格提供程序添加額外的字段?
如何添加到asp.net成員資格提供程序,所以我可以在註冊部分添加一個額外的字段「地址」,並將其保存到數據庫?
我目前看到帳戶模式創建用戶時以下幾點:
public MembershipCreateStatus CreateUser(string userName, string password,
string email)
{
if (String.IsNullOrEmpty(userName))
{ throw new ArgumentException("Value cannot be null or empty.", "userName"); }
if (String.IsNullOrEmpty(password))
{ throw new ArgumentException("Value cannot be null or empty.", "password"); }
if (String.IsNullOrEmpty(email))
{ throw new ArgumentException("Value cannot be null or empty.", "email"); }
MembershipCreateStatus status;
_provider.CreateUser(userName, password, email, null, null, true,
null, out status);
return status;
}
在創建用戶的功能,我也想保存用戶的「地址」。
在register.aspx我加了以下內容:
<div class="editor-label">
<%: Html.LabelFor(m => m.Address) %>
</div>
<div class="editor-field">
<%: Html.TextAreaFor(m => m.Address) %>
</div>
任何想法?
優秀的解決方案,節省了很多麻煩。謝謝,請你解釋第4步。對我來說'.Net'已經在名爲'Migrations'的文件夾中創建了一些類,這些是什麼?如果我發佈該項目會發生什麼? – 2017-08-22 00:39:36
你可以參考https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/hands-on-labs/aspnet-mvc-4-entity-framework-scaffolding-and-migrations細節 – 2017-09-02 05:14:40