编辑用户详细信息时出现错误
我正在尝试按照教程 https://web.archive.org/web/20210306174425/https://www.4guysfromrolla.com/articles/052307-1.aspx
我在VS 2010中的错误列表:
错误 6“评论”不是以下成员 '系统.安全.主体.IPrincipal'。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 21 9 C:\projects\FPOS_v2\
错误 5“电子邮件”不是以下成员的成员 '系统.安全.主体.IPrincipal'。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 20 9 C:\projects\FPOS_v2\
错误 2“FamilyAdmin_edit_user.Private” Sub DeleteUser(发件人作为对象,e作为 System.EventArgs)' 不可访问 在这种情况下,因为它是 '私人的'。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx 140
错误 1“FamilyAdmin_edit_user.Private” Sub UnlockUser(发送者作为对象,e作为 System.EventArgs)' 不可访问 在这种情况下,因为它是 '私人的'。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx 138
错误 7“IsApproved”不是会员 的 '系统.安全.主体.IPrincipal'。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 22 9 C:\projects\FPOS_v2\
错误 8“UnlockUser”不是会员 的 '系统.安全.主体.IPrincipal'。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 88 9 C:\projects\FPOS_v2\
错误 4 属性“用户”是 “只读”。 C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 11 9 C:\projects\FPOS_v2\
edit_user.aspx 的代码是:
<table class="webparts">
<tr>
<th>User Information</th>
</tr>
<tr>
<td class="details" valign="top">
<h3>Roles:</h3>
<asp:CheckBoxList ID="UserRoles" runat="server" />
<h3>Main Info:</h3>
<asp:DetailsView AutoGenerateRows="False" DataSourceID="MemberData"
ID="UserInfo" runat="server" OnItemUpdating="UserInfo_ItemUpdating"
>
<Fields>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem">
</asp:BoundField>
<asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:BoundField DataField="Comment" HeaderText="Comment" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:CheckBoxField DataField="IsApproved" HeaderText="Active User" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem" />
<asp:CheckBoxField DataField="IsLockedOut" HeaderText="Is Locked Out" ReadOnly="true" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem" />
<asp:CheckBoxField DataField="IsOnline" HeaderText="Is Online" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem" />
<asp:BoundField DataField="CreationDate" HeaderText="CreationDate" ReadOnly="True"
HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:BoundField DataField="LastActivityDate" HeaderText="LastActivityDate" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem">
</asp:BoundField>
<asp:BoundField DataField="LastLoginDate" HeaderText="LastLoginDate" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem">
</asp:BoundField>
<asp:BoundField DataField="LastLockoutDate" HeaderText="LastLockoutDate" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:BoundField DataField="LastPasswordChangedDate" HeaderText="LastPasswordChangedDate"
ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:CommandField ButtonType="button" ShowEditButton="true" EditText="Edit User Info" />
</Fields>
</asp:DetailsView>
<div class="alert" style="padding: 5px;">
<asp:Literal ID="UserUpdateMessage" runat="server"> </asp:Literal>
</div>
<div style="text-align: right; width: 100%; margin: 20px 0px;">
<asp:Button ID="Button1" runat="server" Text="Unlock User" OnClick="UnlockUser" OnClientClick="return confirm('Click OK to unlock this user.')" />
<asp:Button ID="Button2" runat="server" Text="Delete User" OnClick="DeleteUser" OnClientClick="return confirm('Are Your Sure?')" />
</div>
<asp:ObjectDataSource ID="MemberData" runat="server" DataObjectTypeName="System.Web.Security.MembershipUser" SelectMethod="GetUser" UpdateMethod="UpdateUser" TypeName="System.Web.Security.Membership">
<SelectParameters>
<asp:QueryStringParameter Name="username" QueryStringField="username" DefaultValue="zora" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr></table>
edit_user.aspx.vb 的代码是我收到错误的地方:
Partial Class FamilyAdmin_edit_user
Inherits System.Web.UI.Page
Private username As String
Private Sub Page_Load()
username = Request.QueryString("username")
If username Is Nothing OrElse username = "" Then
Response.Redirect("users.aspx")
End If
User = Membership.GetUser(username)
UserUpdateMessage.Text = ""
End Sub
Protected Sub UserInfo_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
'Need to handle the update manually because MembershipUser does not have a
'parameterless constructor
User.Email = DirectCast(e.NewValues(0), String)
User.Comment = DirectCast(e.NewValues(1), String)
User.IsApproved = CBool(e.NewValues(2))
Try
' Update user info:
Membership.UpdateUser(User)
' Update user roles:
UpdateUserRoles()
UserUpdateMessage.Text = "Update Successful."
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
Catch ex As Exception
UserUpdateMessage.Text = "Update Failed: " + ex.Message
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
End Try
End Sub
Private Sub Page_PreRender()
' Load the User Roles into checkboxes.
UserRoles.DataSource = Roles.GetAllRoles()
UserRoles.DataBind()
' Disable checkboxes if appropriate:
If UserInfo.CurrentMode <> DetailsViewMode.Edit Then
For Each checkbox As ListItem In UserRoles.Items
checkbox.Enabled = False
Next
End If
' Bind these checkboxes to the User's own set of roles.
Dim userRoles__1 As String() = Roles.GetRolesForUser(username)
For Each role As String In userRoles__1
Dim checkbox As ListItem = UserRoles.Items.FindByValue(role)
checkbox.Selected = True
Next
End Sub
Private Sub UpdateUserRoles()
For Each rolebox As ListItem In UserRoles.Items
If rolebox.Selected Then
If Not Roles.IsUserInRole(username, rolebox.Text) Then
Roles.AddUserToRole(username, rolebox.Text)
End If
Else
If Roles.IsUserInRole(username, rolebox.Text) Then
Roles.RemoveUserFromRole(username, rolebox.Text)
End If
End If
Next
End Sub
Private Sub DeleteUser(ByVal sender As Object, ByVal e As EventArgs)
'Membership.DeleteUser(username, false); // DC: My apps will NEVER delete the related data.
Membership.DeleteUser(username, True)
' DC: except during testing, of course!
Response.Redirect("manage_members.aspx")
End Sub
Private Sub UnlockUser(ByVal sender As Object, ByVal e As EventArgs)
' Dan Clem, added 5/30/2007 post-live upgrade.
' Unlock the user.
User.UnlockUser()
' DataBind the GridView to reflect same.
UserInfo.DataBind()
End Sub
End Class
问题出在用户上。但我不知道如何对此进行排序,因为我对这一切都很陌生。
任何帮助将不胜感激..
谢谢
I am trying to edit and update a selected users details, following the tutorial https://web.archive.org/web/20210306174425/https://www.4guysfromrolla.com/articles/052307-1.aspx
I get the following errors in the Error List in VS 2010:
Error 6 'Comment' is not a member of
'System.Security.Principal.IPrincipal'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 21 9 C:\projects\FPOS_v2\Error 5 'Email' is not a member of
'System.Security.Principal.IPrincipal'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 20 9 C:\projects\FPOS_v2\Error 2 'FamilyAdmin_edit_user.Private
Sub DeleteUser(sender As Object, e As
System.EventArgs)' is not accessible
in this context because it is
'Private'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx 140Error 1 'FamilyAdmin_edit_user.Private
Sub UnlockUser(sender As Object, e As
System.EventArgs)' is not accessible
in this context because it is
'Private'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx 138Error 7 'IsApproved' is not a member
of
'System.Security.Principal.IPrincipal'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 22 9 C:\projects\FPOS_v2\Error 8 'UnlockUser' is not a member
of
'System.Security.Principal.IPrincipal'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 88 9 C:\projects\FPOS_v2\Error 4 Property 'User' is
'ReadOnly'. C:\projects\FPOS_v2\FamilyAdmin\edit_user.aspx.vb 11 9 C:\projects\FPOS_v2\
The code for the edit_user.aspx is:
<table class="webparts">
<tr>
<th>User Information</th>
</tr>
<tr>
<td class="details" valign="top">
<h3>Roles:</h3>
<asp:CheckBoxList ID="UserRoles" runat="server" />
<h3>Main Info:</h3>
<asp:DetailsView AutoGenerateRows="False" DataSourceID="MemberData"
ID="UserInfo" runat="server" OnItemUpdating="UserInfo_ItemUpdating"
>
<Fields>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem">
</asp:BoundField>
<asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:BoundField DataField="Comment" HeaderText="Comment" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:CheckBoxField DataField="IsApproved" HeaderText="Active User" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem" />
<asp:CheckBoxField DataField="IsLockedOut" HeaderText="Is Locked Out" ReadOnly="true" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem" />
<asp:CheckBoxField DataField="IsOnline" HeaderText="Is Online" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem" />
<asp:BoundField DataField="CreationDate" HeaderText="CreationDate" ReadOnly="True"
HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:BoundField DataField="LastActivityDate" HeaderText="LastActivityDate" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem">
</asp:BoundField>
<asp:BoundField DataField="LastLoginDate" HeaderText="LastLoginDate" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem">
</asp:BoundField>
<asp:BoundField DataField="LastLockoutDate" HeaderText="LastLockoutDate" ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:BoundField DataField="LastPasswordChangedDate" HeaderText="LastPasswordChangedDate"
ReadOnly="True" HeaderStyle-CssClass="detailheader" ItemStyle-CssClass="detailitem"></asp:BoundField>
<asp:CommandField ButtonType="button" ShowEditButton="true" EditText="Edit User Info" />
</Fields>
</asp:DetailsView>
<div class="alert" style="padding: 5px;">
<asp:Literal ID="UserUpdateMessage" runat="server"> </asp:Literal>
</div>
<div style="text-align: right; width: 100%; margin: 20px 0px;">
<asp:Button ID="Button1" runat="server" Text="Unlock User" OnClick="UnlockUser" OnClientClick="return confirm('Click OK to unlock this user.')" />
<asp:Button ID="Button2" runat="server" Text="Delete User" OnClick="DeleteUser" OnClientClick="return confirm('Are Your Sure?')" />
</div>
<asp:ObjectDataSource ID="MemberData" runat="server" DataObjectTypeName="System.Web.Security.MembershipUser" SelectMethod="GetUser" UpdateMethod="UpdateUser" TypeName="System.Web.Security.Membership">
<SelectParameters>
<asp:QueryStringParameter Name="username" QueryStringField="username" DefaultValue="zora" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr></table>
The code for the edit_user.aspx.vb is which is where I am getting the error:
Partial Class FamilyAdmin_edit_user
Inherits System.Web.UI.Page
Private username As String
Private Sub Page_Load()
username = Request.QueryString("username")
If username Is Nothing OrElse username = "" Then
Response.Redirect("users.aspx")
End If
User = Membership.GetUser(username)
UserUpdateMessage.Text = ""
End Sub
Protected Sub UserInfo_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
'Need to handle the update manually because MembershipUser does not have a
'parameterless constructor
User.Email = DirectCast(e.NewValues(0), String)
User.Comment = DirectCast(e.NewValues(1), String)
User.IsApproved = CBool(e.NewValues(2))
Try
' Update user info:
Membership.UpdateUser(User)
' Update user roles:
UpdateUserRoles()
UserUpdateMessage.Text = "Update Successful."
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
Catch ex As Exception
UserUpdateMessage.Text = "Update Failed: " + ex.Message
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
End Try
End Sub
Private Sub Page_PreRender()
' Load the User Roles into checkboxes.
UserRoles.DataSource = Roles.GetAllRoles()
UserRoles.DataBind()
' Disable checkboxes if appropriate:
If UserInfo.CurrentMode <> DetailsViewMode.Edit Then
For Each checkbox As ListItem In UserRoles.Items
checkbox.Enabled = False
Next
End If
' Bind these checkboxes to the User's own set of roles.
Dim userRoles__1 As String() = Roles.GetRolesForUser(username)
For Each role As String In userRoles__1
Dim checkbox As ListItem = UserRoles.Items.FindByValue(role)
checkbox.Selected = True
Next
End Sub
Private Sub UpdateUserRoles()
For Each rolebox As ListItem In UserRoles.Items
If rolebox.Selected Then
If Not Roles.IsUserInRole(username, rolebox.Text) Then
Roles.AddUserToRole(username, rolebox.Text)
End If
Else
If Roles.IsUserInRole(username, rolebox.Text) Then
Roles.RemoveUserFromRole(username, rolebox.Text)
End If
End If
Next
End Sub
Private Sub DeleteUser(ByVal sender As Object, ByVal e As EventArgs)
'Membership.DeleteUser(username, false); // DC: My apps will NEVER delete the related data.
Membership.DeleteUser(username, True)
' DC: except during testing, of course!
Response.Redirect("manage_members.aspx")
End Sub
Private Sub UnlockUser(ByVal sender As Object, ByVal e As EventArgs)
' Dan Clem, added 5/30/2007 post-live upgrade.
' Unlock the user.
User.UnlockUser()
' DataBind the GridView to reflect same.
UserInfo.DataBind()
End Sub
End Class
The problem is with the User. But I don't know how to sort this as im new to all this.
Any help would be greatly appreciated..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您忘记定义 MembershipUser 即
当前正在考虑“System.Security.Principal.IPrincipal”中的用户,而不是 MembershipUser。
Because you forgot to define MembershipUser i.e.
Currently it is considering User as in 'System.Security.Principal.IPrincipal' and not MembershipUser.