Partilhar via


CoreWebView2.BasicAuthenticationRequested Event

Definition

BasicAuthenticationRequested event is raised when WebView encounters a Basic HTTP Authentication request as described in https://developer.mozilla.org/docs/Web/HTTP/Authentication, a Digest HTTP Authentication request as described in https://developer.mozilla.org/docs/Web/HTTP/Headers/Authorization#digest, an NTLM authentication or a Proxy Authentication request.

public event EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2BasicAuthenticationRequestedEventArgs> BasicAuthenticationRequested;
member this.BasicAuthenticationRequested : EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2BasicAuthenticationRequestedEventArgs> 
Public Custom Event BasicAuthenticationRequested As EventHandler(Of CoreWebView2BasicAuthenticationRequestedEventArgs) 

Event Type

Examples

_iWebView2.CoreWebView2.BasicAuthenticationRequested += delegate (object sender, CoreWebView2BasicAuthenticationRequestedEventArgs args)
{
    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo credentials in https://authenticationtest.com")]
    args.Response.UserName = "user";
    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo credentials in https://authenticationtest.com")]
    args.Response.Password = "pass";
};
_iWebView2.CoreWebView2.Navigate("https://authenticationtest.com/HTTPAuth");

Remarks

The host can provide a response with credentials for the authentication or cancel the request. If the host sets the Cancel property to false but does not provide either UserName or Password properties on the Response property, then WebView2 will show the default authentication challenge dialog prompt to the user.

Applies to