Using the configuration Builder in ASP.NET 5

The Problem

Managing the configuration data have always been troublsome. Although Microsoft did provided and also updated/upgraded a lot of options from time to time, yet it remains  a challenge most of time. Things get more critical when the configuration data we are concerned is the confidential data like connection string, smtp passwords, API keys etc becase at some point of time, they do get checked in source code or shared across other developers. In one of my prev project faced a similar issue when private key and the Code Signing certificate was accidentally checked in by a developer. The customer had to revoke the certificate which invalidated all the production builds which were deployed to end users as well. Continue reading “Using the configuration Builder in ASP.NET 5”

C# MVC Read Blog Items into an array

Every now and then you would want to enrich your MVC application by displaying a live feed of articles from a blog.
Here is how to do it!

[HttpGet]
public string GetInfo()
{
ArrayList _socialItemsArray = new ArrayList(50);
var i = 0;
var reader2 = System.Xml.XmlReader.Create(“http://myblogurl/feed/”);
var feed2 = System.ServiceModel.Syndication.SyndicationFeed.Load(reader2);
reader2.Close();
foreach (System.ServiceModel.Syndication.SyndicationItem album in feed2.Items)
{

i++;
if (i > 10) { break; }
SocialItem x = new SocialItem();
x.account = “WordPress”;
x.Link = album.Links.First().Uri.ToString();
x.created_at = DateTime.Parse(album.PublishDate.ToString(“g”));

if (album.Title.Text.Length > 90)
{
x.UserDisplayName = album.Title.Text.Substring(0, 87) + “…”;
}
else
{
x.UserDisplayName = album.Title.Text;
}

string postSummary = album.Summary.Text;

if (postSummary.Length >135)
{
postSummary = postSummary.Substring(0, 135);
int lastSpace = postSummary.LastIndexOf(” “);

if (lastSpace != -1)
{
postSummary = postSummary.Substring(0, lastSpace) + “…”;
}
else
{
postSummary = postSummary + “…”;
}
}
x.Content = postSummary;

_socialItemsArray.Add(x);
}

}

If you wish to display the information, just look in the _socialItemsArray and traverse it with a for, foreach or while statement.