【问题标题】:Credentials. C# authorization in Silverlight application证书。 Silverlight 应用程序中的 C# 授权
【发布时间】:2013-08-05 21:11:09
【问题描述】:

我在 IIS 上有基本身份验证。我的 WPF 应用程序使用 WebBrowser 连接到在 IIS 上发布的 Silverlight 应用程序。我尝试了不同的方法来预定义凭据。 像这样:

Uri uri = new Uri("http://1.1.1.1/MyApp");
byte[] authData = System.Text.UnicodeEncoding.UTF8.GetBytes("user: password");
string authHeader = "Authorization: Basic " + Convert.ToBase64String(authData) + "\r\n";
this.browser.Navigate(uri, "", null, authHeader);

但是这个问题不起作用。我只能这样做:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
CredentialCache credentials = new CredentialCache();
credentials.Add(
   uri, "Basic",
   new NetworkCredential("user", "password"));
   request.Credentials = credentials;
   request.PreAuthenticate = true;
   WebResponse response = request.GetResponse();
   this.browser.NavigateToStream(response.GetResponseStream());

但在这种情况下,我不能使用 Silverlight.js 以及所有其他样式和 javascript。

【问题讨论】:

    标签: c# wpf iis browser credentials


    【解决方案1】:

    有一种方法可以通过为您的 WebBrowser 控件提供自定义 IOleClientSite 对象来实现此目的,该对象还实现了 IServiceProviderIAuthenticate 接口。通过IAuthenticate,您可以提供您的凭据。这种方法涉及一些技巧。实现细节可以参考这篇优秀的博客post

    【讨论】:

    • 这对我没有帮助,很难但现在我知道我的凭据和身份验证仅适用于 silverlight 应用程序,当我发布 index.html 文件时一切正常
    猜你喜欢
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 2011-02-20
    • 2017-01-31
    相关资源
    最近更新 更多