RolePrincipal.CachedListChanged Proprietà

Definizione

Ottiene un valore che indica se l'elenco di nomi di ruoli memorizzato con l'oggetto RolePrincipal è stato modificato.

public:
 property bool CachedListChanged { bool get(); };
public bool CachedListChanged { get; }
member this.CachedListChanged : bool
Public ReadOnly Property CachedListChanged As Boolean

Valore della proprietà

true se l'elenco di nomi di ruoli memorizzato con l'oggetto RolePrincipal è stato modificato; in caso contrario, false.

Esempio

Nell'esempio seguente vengono visualizzate informazioni sulla memorizzazione nella cache dei ruoli per l'utente corrente se la gestione dei ruoli è abilitata. Per informazioni sull'abilitazione della gestione dei ruoli, vedere la Roles classe .

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

public void Page_Load()
{

  try
  {
    RolePrincipal r = (RolePrincipal)User;

    IsCachedLabel.Text     = r.IsRoleListCached.ToString();
    CacheChangedLabel.Text = r.CachedListChanged.ToString();
    ExpiredLabel.Text      = r.Expired.ToString();
    VersionLabel.Text      = r.Version.ToString();
    IssueDateLabel.Text    = r.IssueDate.ToString();
    ExpireDateLabel.Text   = r.ExpireDate.ToString();
    CookiePathLabel.Text   = r.CookiePath;

    Msg.Text = "";
  }
  catch (InvalidCastException)
  {
    Msg.Text = "User is not of type RolePrincipal. Are roles enabled?";
  }

}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Role Information</title>
</head>
<body>

<form id="form1" runat="server">

  Role Information for <b><%=User.Identity.Name%></b>.<br />

  <asp:Label id="Msg" runat="Server" ForeColor="maroon" /><br />

  <table border="1" cellpadding="4" cellspacing="4">
    <tr>
      <td>IsRoleListCached</td>
      <td><asp:Label id="IsCachedLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>CachedListChanged</td>  
      <td><asp:Label id="CacheChangedLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>Expired</td>
      <td><asp:Label id="ExpiredLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>Version</td>
      <td><asp:Label id="VersionLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>IssueDate</td>
      <td><asp:Label id="IssueDateLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>ExpireDate</td>
      <td><asp:Label id="ExpireDateLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>CookiePath</td>
      <td><asp:Label id="CookiePathLabel" runat="Server" /></td>
    </tr>
  </table>

</form>


</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Public Sub Page_Load()

    Try
    Dim r As RolePrincipal = CType(User, RolePrincipal)

    IsCachedLabel.Text     = r.IsRoleListCached.ToString()
    CacheChangedLabel.Text = r.CachedListChanged.ToString()
    ExpiredLabel.Text      = r.Expired.ToString()
    VersionLabel.Text      = r.Version.ToString()
    IssueDateLabel.Text    = r.IssueDate.ToString()
    ExpireDateLabel.Text   = r.ExpireDate.ToString()
    CookiePathLabel.Text   = r.CookiePath

    Msg.Text = ""
  Catch e As InvalidCastException
    Msg.Text = "User is not of type RolePrincipal. Are roles enabled?"
  End Try

End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Role Information</title>
</head>
<body>

<form id="form1" runat="server">

  Role Information for <b><%=User.Identity.Name%></b>.<br />

  <asp:Label id="Msg" runat="Server" ForeColor="maroon" /><br />

  <table border="1" cellpadding="4" cellspacing="4">
    <tr>
      <td>IsRoleListCached</td>
      <td><asp:Label id="IsCachedLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>CachedListChanged</td>  
      <td><asp:Label id="CacheChangedLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>Expired</td>
      <td><asp:Label id="ExpiredLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>Version</td>
      <td><asp:Label id="VersionLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>IssueDate</td>
      <td><asp:Label id="IssueDateLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>ExpireDate</td>
      <td><asp:Label id="ExpireDateLabel" runat="Server" /></td>
    </tr>
    <tr>
      <td>CookiePath</td>
      <td><asp:Label id="CookiePathLabel" runat="Server" /></td>
    </tr>
  </table>

</form>


</body>
</html>

Commenti

La CachedListChanged proprietà restituirà true dopo che i nomi dei ruoli sono stati recuperati dal ruolo predefinito e aggiunti alla cache dal GetRoles metodo oppure quando il metodo chiama il IsInRoleIsUserInRole metodo del provider di ruoli predefinito e quindi riceve una risposta di true, risultante dal nome del ruolo Provider passato al IsInRole metodo da aggiungere alla cache.

La CachedListChanged proprietà restituirà anche true se CookieSlidingExpiration è impostata su true e l'oggetto ExpireDate è passato, causando un nuovo ExpireDate set.

Si applica a

Vedi anche