如何在 ASP.NET 中等信任中检索 Google Blogger feed?

发布于 2024-08-07 05:59:05 字数 1151 浏览 4 评论 0原文

我有一个托管在 HostMySite.com 上的 ASP.NET 网站,他们最近将共享帐户更改为以中等信任度运行。在我的网站中,我查询我的 Blogger 帐户并获取要在我的网站上显示的博客文章。

我正在使用 Google.GData.Client v1.4.0.2

检索在本地工作(并且直到在 ISP 调用中等信任为止)。现在我收到以下错误:

[SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint) +147
   System.Net.HttpRequestCreator.Create(Uri Uri) +26
   System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) +216
   System.Net.WebRequest.Create(Uri requestUri) +31
   Google.GData.Client.GDataRequest.EnsureWebRequest() +77
   Google.GData.Client.GDataRequest.Execute() +42
   Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength) +193
   Google.GData.Client.Service.Query(FeedQuery feedQuery) +202

我已经搜索了 Google 文档和在线内容,但无法找到我需要更改的内容。

I have an ASP.NET web site hosted at HostMySite.com and they recently changed the shared accounts to run in medium trust. In my web site I query my Blogger account and get blog posts to display on my web site.

I am using Google.GData.Client v1.4.0.2

The retrieval works locally (and worked until medium trust was invoked at the ISP). Now I receive the following error:

[SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint) +147
   System.Net.HttpRequestCreator.Create(Uri Uri) +26
   System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) +216
   System.Net.WebRequest.Create(Uri requestUri) +31
   Google.GData.Client.GDataRequest.EnsureWebRequest() +77
   Google.GData.Client.GDataRequest.Execute() +42
   Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength) +193
   Google.GData.Client.Service.Query(FeedQuery feedQuery) +202

I've search the Google documentation and on-line but have not been able to find out what I need to change.

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

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

发布评论

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

评论(4

我不吻晚风 2024-08-14 05:59:05

某些主机会将默认信任级别设置为“中”(或类似于中的自定义信任级别),但允许在 web.config 中覆盖它,如下所示:

<system.web>
    <trust level="Full" originUrl="" />
</system.web>

您是否尝试过覆盖它?

Some hosts will set the default trust level to "medium" (or a custom trust level that is similar to medium), but allow it to be overridden in your web.config like so:

<system.web>
    <trust level="Full" originUrl="" />
</system.web>

Have you tried to override it?

徒留西风 2024-08-14 05:59:05

在中等信任度下,Web 应用程序无法打开远程 HTTP 连接。据我所知,没有解决方法。您最好的选择是切换到其他托管服务商,或者与您的托管服务商协商执行 GoDaddy 所做的事情 他们放宽了 WebPermission 设置,专门允许像您这样的场景,其中服务器应用程序必须从 Google 等远程 HTTP 服务器获取数据。

顺便说一句,我并不是说 GoDaddy 是一个出色的托管服务商——他们不是——但他们确实修改了中等信任设置以解决您问题中指出的问题。如果像 GoDaddy 这样的低端托管商愿意这样做,那么您也许可以以此为论据来说服其他托管商也这样做。

Under medium trust, web apps cannot open remote HTTP connections. There's no workaround that I'm aware of. Your best bet is either to switch to another hoster, or to negotiate with your hoster to do what GoDaddy does where they've relaxed their WebPermission settings specifically to allow sccenarios like yours where server apps must fetch data from remote HTTP servers like Google's.

BTW, I'm not saying that GoDaddy is a great hoster-- they're not-- but they did revise their medium trust settings to address the problem noted in your question. And if a low-end hoster like GoDaddy is willing to do this, then you may be able to use this as an argument to convince other hosters to do the same.

好菇凉咱不稀罕他 2024-08-14 05:59:05

您只是检索博客文章吗? RSS feed 不能为您完成这项工作吗?这适用于我为客户做的 GoDaddy 网站。

请记住导入命名空间(可能需要添加对项目的引用):

using System.ServiceModel.Syndication;

protected void Page_Load(object sender, EventArgs e)
    {

        XmlReader xmlReader = System.Xml.XmlReader.Create("URL to blog feed");

        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
        lstLatestNews.DataSource = feed.Items.Take(5);
        lstLatestNews.DataBind();
    }

在 ASPX 页面中:

<asp:ListView ID="lstLatestNews" runat="server">
        <LayoutTemplate>
            <ul id="latest_news">
                <li id="itemPlaceholder" runat="server"></li>
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <li><a href="<%# Eval("Links[0].Uri.AbsoluteUri") %>"><%# Eval("Title.Text") %></a> <em><%# Convert.ToDateTime(Eval("PublishDate.DateTime")).ToString("g") %></em></li>
        </ItemTemplate>
    </asp:ListView>

Are you just retrieving blog posts? Can't an RSS feed do the job for you? This works on a GoDaddy site I did for a client.

Remember to import the namespace (might need to add reference to project):

using System.ServiceModel.Syndication;

protected void Page_Load(object sender, EventArgs e)
    {

        XmlReader xmlReader = System.Xml.XmlReader.Create("URL to blog feed");

        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
        lstLatestNews.DataSource = feed.Items.Take(5);
        lstLatestNews.DataBind();
    }

In the ASPX page:

<asp:ListView ID="lstLatestNews" runat="server">
        <LayoutTemplate>
            <ul id="latest_news">
                <li id="itemPlaceholder" runat="server"></li>
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <li><a href="<%# Eval("Links[0].Uri.AbsoluteUri") %>"><%# Eval("Title.Text") %></a> <em><%# Convert.ToDateTime(Eval("PublishDate.DateTime")).ToString("g") %></em></li>
        </ItemTemplate>
    </asp:ListView>
如若梦似彩虹 2024-08-14 05:59:05

根据您想要使用它的目的,您可以查看 Google AJAX Feed API,它是一个 javascript api,可让您将 rss feed 嵌入到您的网站中。

您将无法从服务器端访问它,它只会显示在用户浏览器中。

如果您试图获取搜索引擎索引的内容,需要将其保存到数据库或以某种方式对其进行操作,那么此解决方案将不适合您。

Google Feed API 文档位于:

Depending on what you want to use this for you could look at the Google AJAX Feed API which is a javascript api that will let you embed rss feeds into your site.

You wouldn't be able to access this from the server side tho, it would only be display in the users browser.

If you are trying to get this content indexed by search engines, need to save it to a database or manipulate it some how then this solution will not work for you.

Google Feed API Docs are at:

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