2012-04-01 43 views
0

我想在創建新用戶時創建表1和表3之間的連接。我必須做什麼?也許以後我會需要更新這個,還有我的另一個問題是如何更新角色?註冊ASP.NET

1.

enter image description here

2. enter image description here

3. enter image description here

有你有這樣的標準控制:

enter image description here

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; 

namespace WebApplicationpomoc.Account 
{ 
    public partial class Register : System.Web.UI.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, false /* createPersistentCookie */); 



      string continueUrl = RegisterUser.ContinueDestinationPageUrl; 
      if (String.IsNullOrEmpty(continueUrl)) 
      { 
       continueUrl = "~/"; 
      } 
      Response.Redirect(continueUrl); 
     } 

    } 
} 


<%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" 
    CodeBehind="Register.aspx.cs" Inherits="WebApplicationpomoc.Account.Register" %> 

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 
</asp:Content> 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
    <asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false" OnCreatedUser="RegisterUser_CreatedUser"> 
     <LayoutTemplate> 
      <asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder> 
      <asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder> 
     </LayoutTemplate> 
     <WizardSteps> 
      <asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server"> 
       <ContentTemplate> 
        <h2> 
         Create a New Account 
        </h2> 
        <p> 
         Use the form below to create a new account. 
        </p> 
        <p> 
         Passwords are required to be a minimum of <%= Membership.MinRequiredPasswordLength %> characters in length. 
        </p> 
        <span class="failureNotification"> 
         <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal> 
        </span> 
        <asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification" 
         ValidationGroup="RegisterUserValidationGroup"/> 
        <div class="accountInfo"> 
         <fieldset class="register"> 
          <legend>Account Information</legend> 
          <p> 
           <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label> 
           <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox> 
           <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" 
            CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required." 
            ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator> 
          </p> 
          <p> 
           <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label> 
           <asp:TextBox ID="Email" runat="server" CssClass="textEntry"></asp:TextBox> 
           <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" 
            CssClass="failureNotification" ErrorMessage="E-mail is required." ToolTip="E-mail is required." 
            ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator> 
          </p> 
          <p> 
           <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label> 
           <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox> 
           <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
            CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required." 
            ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator> 
          </p> 
          <p> 
           <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label> 
           <asp:TextBox ID="ConfirmPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox> 
           <asp:RequiredFieldValidator ControlToValidate="ConfirmPassword" CssClass="failureNotification" Display="Dynamic" 
            ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired" runat="server" 
            ToolTip="Confirm Password is required." ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator> 
           <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" 
            CssClass="failureNotification" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." 
            ValidationGroup="RegisterUserValidationGroup">*</asp:CompareValidator> 
          </p> 
         </fieldset> 
         <p class="submitButton"> 
          <asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User" 
           ValidationGroup="RegisterUserValidationGroup"/> 
         </p> 
        </div> 
       </ContentTemplate> 
       <CustomNavigationTemplate> 
       </CustomNavigationTemplate> 
      </asp:CreateUserWizardStep> 
     </WizardSteps> 
    </asp:CreateUserWizard> 
</asp:Content> 
+0

你已經擁有它們連接thry表2 – Shyju 2012-04-01 15:42:13

+0

無。第二個表爲空我在表1和表3中有數據,但連接在表2中爲空 – RPD 2012-04-01 15:44:05

+0

將數據保存到角色表(對於用戶)時,將記錄添加到第二個表中。 – Shyju 2012-04-01 15:45:01

回答

1

這些只是懷疑,但從你寫的東西看來,你似乎對如何訪問asbnetdb數據庫有模糊的想法。因此,我認爲您正在使用內置的SqlMembershipProvider類 - 您僅提供了連接字符串,而提供程序會自動爲您完成剩下的工作。

如果是這樣,那麼爲用戶分配角色可能最簡單的方法是使用內置的SqlRoleProvider來獲得對角色API的訪問。這是你如何配置這兩個供應商:

http://msdn.microsoft.com/en-us/library/system.web.security.sqlroleprovider.aspx

將用戶添加到一個角色是如此的簡單:

Roles.AddUserToRole("username", "rolename"); 

http://msdn.microsoft.com/en-us/library/system.web.security.roles.addusertorole.aspx

+0

dziękiza pomoc – RPD 2012-04-01 17:21:34

+0

pozdrawiamrównież – 2012-04-01 17:35:49