Why i am getting System.Security exception with RSS feed code

S

Showjumper

I am using the System. ServiceModel.Syndication and linq to creat an RSS
Feed. Everything works fine locally but remotely i get the following error.
Is adjusting the trust level the only way around this or can add some
attribute to the class or is there another option. Trust level adjusting not
an option since on shared hosting. The code for the rss feed folows the
error message.
Thanks
Ashok


Security Exception
Description: The application attempted to perform an operation not allowed
by the security policy. To grant this application the required permission
please contact your system administrator or change the application's trust
level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the
permission of type 'System.Security.Permissions.SecurityPermission,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.


Public Class LinqToRss
Private HttpCon As HttpContext = HttpCon.Current
Private Cache As New Cache
Public Function WriteRss() As String
Dim articleslinq As New ArticlesLINQDataContext
Dim ArticleQuery = From a In articleslinq.Articles Select a.ArticleID,
a.ArticleSummary, a.ArticleTitle, a.DatePublished, a.ArticleText, a.IsActive
Where IsActive = "Active" Order By DatePublished Descending
HttpCon.Response.Buffer = False
HttpCon.Response.Clear()
HttpCon.Response.ContentType = "application/xml"
Using XWriter = XmlWriter.Create(HttpCon.Response.OutputStream)
Dim SyndFeed As New SyndicationFeed
SyndFeed = New SyndicationFeed("RiderDesign.com Articles", "The latest
ASP.NET articles and news from RiderDesign.com.", New
Uri("http://www.RiderDesign.com/rss/default.aspx"))
SyndFeed.Copyright = New TextSyndicationContent("(c) 2007, RiderDesign, LLC.
All rights reserved.")
SyndFeed.Authors.Add(New SyndicationPerson("(e-mail address removed)",
"RiderDesign.com", "http://riderdesign.com"))
SyndFeed.Language = "en-US"
Dim SyndFeedItems As New List(Of SyndicationItem)
For Each a In ArticleQuery
Dim SyndItem As New SyndicationItem
SyndItem.Id = Convert.ToString(a.ArticleID)
SyndItem.PublishDate = CType(a.DatePublished, DateTimeOffset)
SyndItem.Title =
TextSyndicationContent.CreatePlaintextContent(a.ArticleTitle)
SyndItem.Summary =
TextSyndicationContent.CreatePlaintextContent(a.ArticleSummary)
SyndItem.AddPermalink(New
Uri("http://riderdesign.com/articles/displayarticle.aspx?ArticleID=" &
a.ArticleID))
SyndFeedItems.Add(SyndItem)
Next
SyndFeed.Items = SyndFeedItems
SyndFeed.SaveAsRss20(XWriter)
XWriter.Flush()
XWriter.Close()
Cache.Insert("RssFeed", XWriter.ToString(), Nothing,
DateTime.Now.AddHours(12), TimeSpan.Zero)
Return XWriter.ToString
End Using
End Function
 
S

Showjumper

Fixed it
Showjumper said:
I am using the System. ServiceModel.Syndication and linq to creat an RSS
Feed. Everything works fine locally but remotely i get the following error.
Is adjusting the trust level the only way around this or can add some
attribute to the class or is there another option. Trust level adjusting
not an option since on shared hosting. The code for the rss feed folows the
error message.
Thanks
Ashok


Security Exception
Description: The application attempted to perform an operation not allowed
by the security policy. To grant this application the required permission
please contact your system administrator or change the application's trust
level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the
permission of type 'System.Security.Permissions.SecurityPermission,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.


Public Class LinqToRss
Private HttpCon As HttpContext = HttpCon.Current
Private Cache As New Cache
Public Function WriteRss() As String
Dim articleslinq As New ArticlesLINQDataContext
Dim ArticleQuery = From a In articleslinq.Articles Select a.ArticleID,
a.ArticleSummary, a.ArticleTitle, a.DatePublished, a.ArticleText,
a.IsActive Where IsActive = "Active" Order By DatePublished Descending
HttpCon.Response.Buffer = False
HttpCon.Response.Clear()
HttpCon.Response.ContentType = "application/xml"
Using XWriter = XmlWriter.Create(HttpCon.Response.OutputStream)
Dim SyndFeed As New SyndicationFeed
SyndFeed = New SyndicationFeed("RiderDesign.com Articles", "The latest
ASP.NET articles and news from RiderDesign.com.", New
Uri("http://www.RiderDesign.com/rss/default.aspx"))
SyndFeed.Copyright = New TextSyndicationContent("(c) 2007, RiderDesign,
LLC. All rights reserved.")
SyndFeed.Authors.Add(New SyndicationPerson("(e-mail address removed)",
"RiderDesign.com", "http://riderdesign.com"))
SyndFeed.Language = "en-US"
Dim SyndFeedItems As New List(Of SyndicationItem)
For Each a In ArticleQuery
Dim SyndItem As New SyndicationItem
SyndItem.Id = Convert.ToString(a.ArticleID)
SyndItem.PublishDate = CType(a.DatePublished, DateTimeOffset)
SyndItem.Title =
TextSyndicationContent.CreatePlaintextContent(a.ArticleTitle)
SyndItem.Summary =
TextSyndicationContent.CreatePlaintextContent(a.ArticleSummary)
SyndItem.AddPermalink(New
Uri("http://riderdesign.com/articles/displayarticle.aspx?ArticleID=" &
a.ArticleID))
SyndFeedItems.Add(SyndItem)
Next
SyndFeed.Items = SyndFeedItems
SyndFeed.SaveAsRss20(XWriter)
XWriter.Flush()
XWriter.Close()
Cache.Insert("RssFeed", XWriter.ToString(), Nothing,
DateTime.Now.AddHours(12), TimeSpan.Zero)
Return XWriter.ToString
End Using
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top