How to get Google Blogger feed in ASP.NET Trust framework?

I have an ASP.NET website hosted at HostMySite.com and they recently changed shared accounts to work in a trust environment. On my website, I request my Blogger account and get blog posts to display on my website.

I am using Google.GData.Client v1.4.0.2

The lookup is done locally (and worked until medium traffic was called at the ISP). Now I am getting 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 searched google documentation and online but couldn't find out what I need to change.

+2


source to share


4 answers


Some hosts set the default trust level to "medium" (or a custom trust level similar to the facility), but allow you to override it in your web.config as follows:

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

      



Have you tried to override it?

+1


source


In a medium-trusted environment, web applications cannot open remote HTTP connections. There is no workaround that I am aware of. Your best bet is to either switch to a different hoster, or arrange with the hoster about what GoDaddy is doing , where they toned down their WebPermission settings specifically to allow sccenarios like yours, where server applications have to fetch data from remote HTTP servers like Google.



By the way, I'm not saying that GoDaddy is a great host - they don't ... but they've revised their average trust settings to address the issue noted in your question. And if a hosting host like GoDaddy is willing to do it, then you can use that as an argument to convince other hosts to do the same.

0


source


Are you just fetching blog posts? Could an RSS feed do the job for you? This works on the GoDaddy site I made for a client.

Don't forget to import the namespace (you might need to add a project reference):

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();
    }

      

From 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>

      

0


source


Depending on what you want to use to do this, you can look at the Google AJAX API, which is a javascript api that will allow you to inject rss feeds into your site.

You won't be able to access this from the server side tho, it will only show up in the users browser.

If you are trying to get this content indexed by search engines you need to store it in a database or manipulate it in some way as this solution will not work for you.

The Google Feed API docs are located at:

0


source







All Articles