ASP.NET을 처음 사용했습니다.사용자 만들기 마법사 - null 참조 예외가 사용자 코드에 의해 처리되지 않았습니다.
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="CreateUsers.aspx.cs" Inherits="Membership_CreateUser" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<h2>
Create Users</h2>
<p>
<asp:CreateUserWizard ID="RegisterWithRoles" runat="server"
ContinueDestinationPageUrl="~/Default.aspx" LoginCreatedUser="False"
onactivestepchanged="RegisterWithRoles_ActiveStepChanged">
<WizardSteps>
<asp:CreateUserWizardStep runat="server" />
<asp:WizardStep ID="SpecifyRoles" runat="server" AllowReturn="False"
StepType="Step" Title="Specify Roles">
<asp:CheckBoxList ID="RoleList" runat="server">
</asp:CheckBoxList>
</asp:WizardStep>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
</p>
<p>
</p>
</asp:Content>
및 코드 뒤에 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class Membership_CreateUser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Reference the SpecifyRolesStep WizardStep
WizardStep SpecifyRolesStep = RegisterWithRoles.FindControl("SpecifyRolesStep") as
WizardStep;
// Reference the RoleList CheckBoxList
CheckBoxList RoleList = SpecifyRolesStep.FindControl("RoleList") as CheckBoxList;
// Bind the set of roles to RoleList
RoleList.DataSource = Roles.GetAllRoles();
RoleList.DataBind();
}
}
protected void RegisterWithRoles_ActiveStepChanged(object sender, EventArgs e)
{
// Have we JUST reached the Complete step?
if (RegisterWithRoles.ActiveStep.Title == "Complete")
{
// Reference the SpecifyRolesStep WizardStep
WizardStep SpecifyRolesStep = RegisterWithRoles.FindControl("SpecifyRoles") as
WizardStep;
// Reference the RoleList CheckBoxList
CheckBoxList RoleList = SpecifyRolesStep.FindControl("RoleList") as CheckBoxList;
// Add the checked roles to the just-added user
foreach (ListItem li in RoleList.Items)
{
if (li.Selected)
Roles.AddUserToRole(RegisterWithRoles.UserName, li.Text);
}
}
}
}
나는 오류
가 계속 나는 영문 파일이 튜토리얼 여기 http://www.asp.net/web-forms/tutorials/security/roles/assigning-roles-to-users-cs의 4 단계에서 가져온 createUserWiazrd 이름 RegisterUserWithRoles이다가
null reference exception was unhandled by user code - Object reference not set to an instance of an object.
다섯 가지 역할이 있는데, 나는를 사용하여 확인했습니다.. 이 오류의 원인을 이해할 수 있도록 도와주십시오.
미리 감사드립니다. 나는이 기능을 위해 제공되는 마법사를 사용하지 않고, 스택 추적이 유용 할 수 있지만
예외의 스택 추적은 무엇입니까? –