Rss & SiteMap
爱心论坛 http://www.zqax.net/bbs/
值 | 描述 |
None | 没有激活的ASP.NET认证服务。请注意IIS认证服务仍然存在。 |
Windows | ASP.NET认证服务给当前请求附加上WindowsPrincipal (System.Security.Principal.WindowsPrincipal),以保证根据NT用户或组进行授权。 |
Forms | ASP.NET认证服务管理cookie并把未认证的用户重定向到登录页面。它通常在IIS允许匿名访问应用程序的时候使用。 |
Passport | ASP.NET认证服务提供了Passport SDK (你必须安装)的一个方便的包装。 |
<configuration> <system.web> <authentication mode="Forms"/> </system.web> </configuration> |
Login.aspx <%@ Page Language="VB" MasterPageFile="~/Site.master"%> <asp:Content ID="Content1" ContentPlaceHolderId="MainBody" runat="server"> <asp:login ID="Login1" runat="server" createuserurl="CreateUser.aspx" createusertext="Create a New Account" /> </asp:Content> CreateUser.aspx <%@ Page Language="VB" MasterPageFile="~/Site.master"%> <asp:Content ID="Content1" ContentPlaceHolderId="MainBody" runat="server"> <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" continuedestinationpageurl="Home.aspx"/><br /> <a href="Home.aspx">Return to Default Home Page</a><br /> <a href="HomeLoginView.aspx">Return to LoginView Home Page</a><br /> <a href="HomeChangePassword.aspx">Return to ChangePassword Home Page</a><br /> </asp:Content> |
<%@ Page Language="VB" MasterPageFile="~/Site.master"%> <asp:Content ID="Content1" ContentPlaceHolderId="MainBody" runat="server"> <asp:loginview ID="LoginView1" runat="server"> <loggedintemplate> <h1> <asp:loginname id="LoginName1" runat="server" formatstring="Welcome {0}" /> </h1> </loggedintemplate> <anonymoustemplate> <h1>Welcome to Login Controls</h1> <asp:login ID="Login1" runat="server" createuserurl="CreateUser.aspx" createusertext="Create a New Account" /> </anonymoustemplate> </asp:LoginView> </asp:Content> |
<%@ Page Language="VB" MasterPageFile="~/Site.master"%> <asp:Content ID="Content1" ContentPlaceHolderId="MainBody" runat="server"> <asp:ChangePassword ID="ChangePassword1" runat="server" createuserurl="CreateUser.aspx" createusertext="Create a New Account" canceldestinationpageurl="HomeChangePassword.aspx" displayusername="true" continuedestinationpageurl="HomeChangePassword.aspx"/> </asp:Content> |
<script runat="server"> Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim userName As String = txtUserId.Text '这个值式加密的或散列过,不会显示 Dim password As String = txtPassword.Text Dim email As String = txtEmail.Text Dim passwordQuestion As String = ddlPasswordQuestion.SelectedValue '这个值式加密的或散列过,不会显示 Dim passwordAnswer As String = txtPasswordAnswer.Text Dim result As MembershipCreateStatus Membership.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, True, result) lblResults.Visible = True Select Case result Case MembershipCreateStatus.Success txtUserId.Text = Nothing txtPassword.Text = Nothing txtEmail.Text = Nothing ddlPasswordQuestion.SelectedIndex = -1 txtPasswordAnswer.Text = Nothing lblResults.Text = "User successfully created!" Case MembershipCreateStatus.InvalidUserName lblResults.Text = "The username format was invalid. Please enter a different username." Case MembershipCreateStatus.InvalidPassword lblResults.Text = "The password was invalid: A password cannot be an empty string and must also meet the pasword strength requirements of the configured provider. Please enter a new password." Case MembershipCreateStatus.InvalidEmail lblResults.Text = "The email format was invalid. Please enter a different username." Case MembershipCreateStatus.InvalidQuestion lblResults.Text = "The password question format was invalid. Please enter a different question." Case MembershipCreateStatus.InvalidAnswer lblResults.Text = "The password answer format was invalid. Please enter a different answer." Case MembershipCreateStatus.DuplicateUsername lblResults.Text = "The username is already in use. Please enter a new username." Case MembershipCreateStatus.DuplicateEmail lblResults.Text = "The email address is already in use. Please enter a different email address." Case Else lblResults.Text = "An error occurred while creating the user." End Select End Sub </script> |
<script runat="server"> Protected memUser As MembershipUser Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) memUser = Membership.GetUser() End Sub Sub linkLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) FormsAuthentication.SignOut() Roles.DeleteCookie() FormsAuthentication.RedirectToLoginPage() End Sub </script> User Name/ID: <% = Server.HtmlEncode(memUser.Username) %> Email:<% = Server.HtmlEncode(memUser.Email) %> |
Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e as DetailsViewUpdateEventArgs) '必须手动处理更新操作,因为MembershipUser 没有参数化的构造函数 Dim memUser as MembershipUser = Membership.GetUser() memUser.Email = CStr(e.NewValues(0)) memUser.Comment = CStr(e.NewValues(1)) Try Membership.UpdateUser(memUser) e.Cancel = true DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) Catch ex as Exception Response.Write("<div>The following error occurred:<font color='red'> " + ex.Message + "</font></div>") e.Cancel = true End Try End Sub |
Sub btnUnlockUser_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim memUser as MembershipUser = Membership.GetUser(txtUserName.Text) If (Not memUser is Nothing And memUser.IsLockedOut = true) memUser.UnlockUser() End If '刷新被选中用户的信息 DetailsView1.DataBind() End Sub |
<script runat="server"> Sub btnDeleteCurrentUser_Click(ByVal sender As Object, ByVal e As System.EventArgs) If (Membership.DeleteUser(User.Identity.Name)) Then FormsAuthentication.SignOut() Roles.DeleteCookie() Response.Redirect("~/CreatingUsers.aspx") Else lblResult.Visible = True lblResult.Text = "The Membership user was not deleted." End If End Sub </script> |
Sub btnCreateRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim roleName As String = txtCreateRole.Text Try Roles.CreateRole(roleName) lblResults.Text = Nothing lblResults.Visible = False txtCreateRole.Text = Nothing Catch ex As Exception lblResults.Text = "Could not create the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try End Sub Sub btnDeleteRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) If (lbxAvailableRoles.SelectedIndex <> -1) Then Try Roles.DeleteRole(lbxAvailableRoles.SelectedValue) lblResults.Text = Nothing lblResults.Visible = False Catch ex As Exception lblResults.Text = "Could not delete the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try End If End Sub |
Sub btnAddUserToRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) If (lbxAvailableRoles.SelectedIndex <> -1) Then Dim selectedRole As String = lbxAvailableRoles.SelectedValue If Not Roles.IsUserInRole(selectedRole) Then Try Roles.AddUserToRole(User.Identity.Name, selectedRole) RefreshCurrentRolesListBox() Catch ex As Exception lblResults.Text = "Could not add the user to the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try Else lbxAvailableRoles.SelectedIndex = -1 End If End If End Sub Sub btnDeleteUserFromRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim selectedRole As String = lbxUserRoles.SelectedValue If (lbxUserRoles.SelectedIndex <> -1) Then Try Roles.RemoveUserFromRole(User.Identity.Name, selectedRole) RefreshCurrentRolesListBox() Catch ex As Exception lblResults.Text = "Could not remove the user from the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try End If End Sub |
<location path="administrators_role"> <system.web> <authorization> <allow roles="Administrators" /> <deny users="*"/> </authorization> </system.web> </location> |
<asp:Label ID="Label1" runat="server" Text=<%# User.IsInRole("Administrators") %> /> <asp:Label ID="Label2" runat="server" Text=<%# Roles.IsUserInRole("Regular Users") %> /> <asp:Label ID="Label3" runat="server" Text=<%# (CType(User,RolePrincipal)).IsInRole("Power Users") %> /> |