Silverlight 4 Web客户端身份验证-有人可以使用它吗?

发布于 2024-08-12 07:48:56 字数 1149 浏览 4 评论 0原文

因此,新的 Silverlight 4 Beta 最好的部分之一是他们最终实现了网络堆栈中缺失的重要功能 - 网络凭据!

在下面,我有一个有效的请求设置,但由于某种原因,当请求返回时我收到“安全错误” - 这是因为 twitter.com 拒绝了我的 api 调用还是我在代码中丢失了某些内容?

最好指出的是,当我看到这段代码通过 fiddler 执行时,它显示跨域的 xml 文件已成功下拉,但这是 fiddler 显示的最后一个请求......

public void RequestTimelineFromTwitterAPI()
        {
               WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);

               WebClient myService = new WebClient();
               myService.AllowReadStreamBuffering = true;
               myService.UseDefaultCredentials = false;
               myService.Credentials = new NetworkCredential("username", "password");
               myService.UseDefaultCredentials = false;

               myService.OpenReadCompleted += new OpenReadCompletedEventHandler(TimelineRequestCompleted);
               myService.OpenReadAsync(new Uri("https://twitter.com/statuses/friends_timeline.xml"));
        }

        public void TimelineRequestCompleted(object sender, System.Net.OpenReadCompletedEventArgs e)
        {
            //anytime I query for e.Result I get a security error
        }

So one of the best parts about the new Silverlight 4 beta is that they finally implemented the big missing feature of the networking stack - Network Credentials!

In the below I have a working request setup, but for some reason I get a "security error" when the request comes back - is this because twitter.com rejected my api call or something that I'm missing in code?

It might be good to point out that when I watch this code execute via fiddler it shows that the xml file for cross domain is pulled down successfully, but that is the last request shown by fiddler ...

public void RequestTimelineFromTwitterAPI()
        {
               WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);

               WebClient myService = new WebClient();
               myService.AllowReadStreamBuffering = true;
               myService.UseDefaultCredentials = false;
               myService.Credentials = new NetworkCredential("username", "password");
               myService.UseDefaultCredentials = false;

               myService.OpenReadCompleted += new OpenReadCompletedEventHandler(TimelineRequestCompleted);
               myService.OpenReadAsync(new Uri("https://twitter.com/statuses/friends_timeline.xml"));
        }

        public void TimelineRequestCompleted(object sender, System.Net.OpenReadCompletedEventArgs e)
        {
            //anytime I query for e.Result I get a security error
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生未歇 2024-08-19 07:48:56

我发现有 2 个问题导致此请求引发安全异常

1) - 在 这个视频,作者:Tim Heuer 事实证明我的 VS2010 w/ Silverlight 4 工具包安装与最终版本不匹配,所以我错过了显示的选项“浏览器外设置”对话框,提供“在浏览器外部运行时需要提升信任”复选框。

在上面列出的视频中,Tim 检查了这一点,以便 Silverlight 应用程序可以与 twitter API 对话,

但因为我的应用程序没有此选项,所以我必须手动编辑 xml 文件,使其如下所示。您可以在项目文件夹的属性下或直接在 Visual Studio 中找到此 xml。

<OutOfBrowserSettings ShortName="TrustedNetworkApp Application" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>TrustedNetworkApp Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
    <WindowSettings Title="TrustedNetworkApp Application" Height="480" Width="640" />
  </OutOfBrowserSettings.WindowSettings>
  <OutOfBrowserSettings.SecuritySettings>
    <SecuritySettings ElevatedPermissions="Required" />
  </OutOfBrowserSettings.SecuritySettings>
  <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

请注意 **安全设置 ElevatedPermissions="Required"

保存此设置后,相当于像蒂姆在视频中那样检查此设置。

2) - 当我观看 Tim 的视频时,我注意到你必须在浏览器之外对其进行调试才能使其正常工作。因此,安装该应用程序并在浏览器外运行它。这个应用程序现在可以运行了。

我将写一篇简短的博客文章来总结我在测试版中使用网络堆栈的经验,并为感兴趣的人提供链接。

更新

我终于写了一篇博客帖子关于我使用 Silverlight 4 构建浏览器外 Twitter 客户端的经验(如果有人感兴趣的话)。

I found 2 issues that caused this request to throw the security exception

1) - In this video by Tim Heuer it turns out my VS2010 w/ Silverlight 4 toolkit installation didn't match the final build so I'm missing the option that shows up in the "out of browser settings" dialog that provides the checkbox for "Require elevated trust when running outside the browser".

In the video listed above Tim checks this so the Silverlight app can talk to the twitter API

But because my application didn't have this option I had to manually edit the xml file so it looked like the below. You can find this xml under properties in the project folder or inside visual studio directly.

<OutOfBrowserSettings ShortName="TrustedNetworkApp Application" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>TrustedNetworkApp Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
    <WindowSettings Title="TrustedNetworkApp Application" Height="480" Width="640" />
  </OutOfBrowserSettings.WindowSettings>
  <OutOfBrowserSettings.SecuritySettings>
    <SecuritySettings ElevatedPermissions="Required" />
  </OutOfBrowserSettings.SecuritySettings>
  <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

Notice the **security settings ElevatedPermissions="Required"

After you save this it's equivalent to checking this as Tim did in the video.

2) - as I was watching that video by Tim I noticed that you have to debug this outside of the browser to get it working. So install the app and run it outside the browser. This app now works.

I'll write a short blog post to summarize my experience with the networking stack under the beta and link to it for anyone interested.

Update

I finally wrote a blog post about my experience building an out of browser twitter client using Silverlight 4 if anyone is interested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文