WebClientProtocol.Credentials Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta le credenziali di sicurezza per l'autenticazione client del servizio Web XML.
public:
property System::Net::ICredentials ^ Credentials { System::Net::ICredentials ^ get(); void set(System::Net::ICredentials ^ value); };
public System.Net.ICredentials Credentials { get; set; }
member this.Credentials : System.Net.ICredentials with get, set
Public Property Credentials As ICredentials
Valore della proprietà
Oggetto ICredentials per il client del servizio Web XML.
Esempio
L'esempio seguente è un web form ASP.NET, che chiama un servizio Web XML denominato Math. All'interno della EnterBtn_Click funzione, il Web Form imposta in modo esplicito le credenziali di autenticazione usando la Credentials proprietà . Il nome utente, la password e il dominio vengono passati al costruttore per la NetworkCredential classe .
Importante
In questo esempio è presente una casella di testo che accetta l'input dell'utente, che rappresenta una potenziale minaccia per la sicurezza. Per impostazione predefinita, ASP.NET pagine Web verificare che l'input dell'utente non includa elementi SCRIPT o HTML. Per altre informazioni, vedere.
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<html>
<script language="C#" runat="server">
void EnterBtn_Click(Object Src, EventArgs E)
{
MyMath.Math math = new MyMath.Math();
// Obtain password from a secure store.
String SecurelyStoredPassword = String.Empty;
// Set the client-side credentials using the Credentials property.
ICredentials credentials = new NetworkCredential("Joe",SecurelyStoredPassword,"mydomain");
math.Credentials = credentials;
int total = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text));
Total.Text = "Total: " + total.ToString();
}
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
<html>
<script language="VB" runat="server">
Sub EnterBtn_Click(src As Object, e As EventArgs)
Dim math As New MyMath.Math()
' Obtain password from a secure store.
Dim SecurelyStoredPassword As String = String.Empty
' Set the client-side credentials using the Credentials property.
Dim credentials = New NetworkCredential("Joe", SecurelyStoredPassword, "mydomain")
math.Credentials = credentials
Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
Total.Text = "Total: " + iTotal.ToString()
End Sub
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>
Commenti
Quando si usa la Credentials proprietà , un client del servizio Web XML deve creare un'istanza di una classe che implementa ICredentials, ad esempio NetworkCredential, e quindi impostare le credenziali client specifiche per il meccanismo di autenticazione. La NetworkCredential classe può essere usata per impostare le credenziali di autenticazione usando i meccanismi di autenticazione di base, digest, NTLM e Kerberos.
Quando la Credentials proprietà è impostata su CredentialCache.DefaultCredentials , il client negozia con il server per eseguire l'autenticazione Kerberos e/o NTLM a seconda della configurazione del server.