views:

296

answers:

4

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.

Thanks

A: 

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.

Justin Grant
A: 

The way MS implement this Medium Trust business is rather poor. Restricting reflection on assemblies in your own bin or restricting calls to methods in other namespaces in your own assembly are simply ridiculous. The ignorance of hosts like HostMySite (aka hosting.com) in refusing to adjust trust levels make things worse for their own detriment. I used to have a site at HostMySite and had to move it to ServerIntellect for this very reason.

Dot Nut
A: 

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>
subkamran
A: 

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?

bakes