我在WebForms項目中使用成員資格提供程序(身份的前體)。我能夠讓用戶開箱即用。我註冊了一些用戶,ASP.Net在我的數據庫中創建了下列表格。ASP.Net成員資格(Visual Studio 2012和Web窗體)
dbo.Memberships
dbo.Profiles
dbo.Rules
dbo.Users
dbo.UsersInRoles
dbo.UsersOpenAuthAccounts
dbo.UsersOpenAuthData
我敢肯定,這是成員所需的整個表格組。我已成功限制訪問我的網站以登錄用戶。我創建了角色,並開始將網站中的部分定義爲僅限具有某些角色的用戶。
我的問題是爲用戶添加額外的字段。
到目前爲止,我已經走了簡單地將其他信息添加到我的web.config文件的配置文件部分的路線。
<authentication mode="Forms">
<forms loginUrl="/Account/Login.aspx" timeout="2880" defaultUrl="~/Projects.aspx" />
</authentication>
<authorization>
<deny users="?" />
<deny roles="Admin" />
</authorization>
<profile defaultProvider="SqlProvider">
<providers >
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
<properties>
<add name="fname" />
<add name="lname" />
<add name="skype" />
<add name="phone" />
</properties>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
<providers>
<add connectionStringName="DefaultConnection" applicationName="/" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</providers>
</roleManager>
與
所以到位,主要的變化是,我加爲了嘗試並添加額外的用戶相關領域如下:
<profile defaultProvider="SqlProvider">
<providers >
...
</providers>
<properties>
<add name="fname" />
<add name="lname" />
<add name="skype" />
<add name="phone" />
</properties>
</profile>
我目前有以下在我的web.config中定義
我也更新了賬戶/ Register.aspx頁,現在看起來是這樣的:
<%@ Page Title="Register" Language="C#" MasterPageFile="~/DashUser.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="ArchiTrak.Account.Register" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="BodyContent">
<h2 class="form-signin-heading raleway"><%: Title %>.</h2>
<asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatedUser="RegisterUser_CreatedUser">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
<asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="RegisterUserWizardStep">
<ContentTemplate>
<div class="container">
<div class="row">
<div class="col-md-6">
<p class="raleway">
Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.
</p>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="ErrorMessage" />
</p>
<asp:TextBox class="form-control" runat="server" ID="UserName" placeholder="User Name"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName"
CssClass="field-validation-error" ErrorMessage="The user name field is required." />
<asp:TextBox class="form-control" runat="server" ID="fname" placeholder="First Name"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="fname"
CssClass="field-validation-error" ErrorMessage="The First Name field is required." />
<asp:TextBox class="form-control" runat="server" ID="lname" placeholder="Last Name"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="lname"
CssClass="field-validation-error" ErrorMessage="The Last Name field is required." />
<asp:TextBox class="form-control" runat="server" ID="phone" placeholder="Phone Number"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="phone"
CssClass="field-validation-error" ErrorMessage="The Phone field is required." />
<asp:TextBox class="form-control" runat="server" ID="skype" placeholder="Skype Account"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="skype"
CssClass="field-validation-error" ErrorMessage="The Skype field is required." />
<asp:TextBox class="form-control" runat="server" ID="Email" TextMode="Email" placeholder="Email"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="Email"
CssClass="field-validation-error" ErrorMessage="The email address field is required." />
<asp:TextBox class="form-control" runat="server" ID="Password" TextMode="Password" placeholder="Password"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="The password field is required."/>
<asp:TextBox class="form-control" runat="server" ID="ConfirmPassword" TextMode="Password" placeholder="Password"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The confirm password field is required." />
<asp:CompareValidator runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
<br />
<asp:Button runat="server" CommandName="MoveNext" Text="Register" CssClass="btn btn-lg btn-primary btn-block"/>
</div>
</div>
</div>
</ContentTemplate>
<CustomNavigationTemplate />
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</asp:Content>
我已經添加了阿迪收集第一個&姓氏,Skype和電話號碼。但是,當我提交新用戶的註冊時,數據庫中的配置文件表中沒有顯示任何內容。
的Register.aspx.cs看起來是這樣的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Membership.OpenAuth;
namespace ArchiTrak.Account
{
public partial class Register : Page
{
protected void Page_Load(object sender, EventArgs e)
{
RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
}
protected void RegisterUser_CreatedUser(object sender, EventArgs e)
{
FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);
string continueUrl = RegisterUser.ContinueDestinationPageUrl;
if (!OpenAuth.IsLocalUrl(continueUrl))
{
continueUrl = "~/Projects.aspx";
}
Response.Redirect(continueUrl);
}
}
}
從我讀有關添加附加信息的輪廓方式是,它只是類似上面我所做過的最小的修改工作。 AM我錯過了什麼?是否有一些好的教程一步一步地使用Web窗體來完成這個任務?我一直在尋找信息和教程所以我發現了角色&配置文件的微軟鏈接。這就是我如何得到這一點。我用於Identity,但不能在此項目中使用它。任何幫助,將不勝感激,或只是一個正確的方向踢。
配置文件僅在網站項目模板開箱即可使用。你將不得不實施自定義配置文件,但有很多鏈接到這一點上已經:) – IrishChieftain
這並沒有幫助我很多。只有網站項目模板?這聽起來不對...... –
我正在使用基本的WebForms模板。林不知道你的意思。我的應用程序正在與角色和註冊開箱即用,爲什麼我不能使用配置文件? –