2014-06-05 114 views
0

我正在寫一個簡單的asp.net應用程序與實體框架和mvc。登錄系統和存儲

我從一個實際包含簡單帳戶創建和登錄系統的模板開始。不過,我希望將帳戶詳細信息存儲在數據庫中。

var user = new ApplicationUser() { UserName = model.UserName }; 
var result = await UserManager.CreateAsync(user); 
if (result.Succeeded) 
{ 
    result = await UserManager.AddLoginAsync(user.Id, info.Login); 

我想問一下這兩個東西

  1. 我可以使用的UserManager類來存儲,在我自己的數據庫結構,管理用戶?
  2. 存儲用戶名/密碼的示例(默認.net mvc應用程序)在哪裏?
+0

ASP什麼版本的? – Pseudonym

+0

你可以在你的數據庫中創建asp.net表,如果你喜歡,你可以從那裏操作。 – Aristos

+0

我建議你製作自己的登錄系統。爲什麼?因爲您可以通過該登錄系統執行任何您想要的操作。 –

回答

1

從我看到的,或者我的猜測,你正在使用ASP.Net MVC 5,這是腳手架代碼。

  1. 我可以使用UserManager類來存儲和管理我自己的數據庫結構中的用戶嗎? 是的,您可以使用UserManager對象來存儲用戶。你會想要做的第一件事情是打開IdentityModels.cs,如果需要修改類的任何額外的字段添加:

    public partial class ApplicationUser : IdentityUser 
    
    { 
        public string FirstName { get; set; } 
        public string LastName { get; set; } 
        //Etc 
    } 
    

哪裏例子(默認.NET MVC應用程序)中存儲的用戶名/密碼? 看看你的web.config。什麼我有我的開發機器上的一個例子:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20140606091757.mdf;Initial Catalog=aspnet-WebApplication1-20140606091757;Integrated Security=True" providerName="System.Data.SqlClient" /> 

這意味着,你需要連接到你的web.config中指定的數據源。在Visual Studio展出單擊所有文件:

Show all files in VS 2013

然後,在mdf文件,這將打開服務器資源管理器中雙擊。瀏覽到AspNetUsers表:

Browse DB

+0

令人驚訝的是,你可以得到這麼多愚蠢的答案,然後一個有用的人來,謝謝。 –