I have created a Blog in my site and change its layout. I'm using a webpart which is giving 401 error on public facing site.
My Code is:
public void CustomBlogLayout()
{
SPSite thisSite = SPContext.Current.Site;
using (SPWeb targetWeb = thisSite.AllWebs["/en-us/blogs/"])
{
SPList Forms = targetWeb.Lists["Posts"];
SPQuery qry = new SPQuery();
qry.Query = @"<Query>" +
"<OrderBy>" +
"<FieldRef Ascending='FALSE' Name='Modified' />" +
"</OrderBy>" +
"</Query>";
SPListItemCollection SPLIC = Forms.GetItems(qry);
LiteralControl print = null;
string tlink = string.Empty;
foreach (SPListItem item in SPLIC)
{
tlink = "/en-us/blogs/Lists/Posts/Post.aspx?&ID=" + item.ID;
string[] authorInfo = item["Author"].ToString().Split(';');
string authorId = authorInfo[0];
string author = authorInfo[1].Replace("#", string.Empty);
string alink = "/en-us/blogs/_layouts/userdisp.aspx?ID=" + Convert.ToInt32(authorId);
string body = item["Body"].ToString();
print = new LiteralControl("<div class='ms-PostTitle' ><a href=" + tlink + " >" + item["Title"].ToString() + "</a></div>" +
"<div class='ms-PostFooter' > by " + "<a href=" + alink + " >" + author + "</a>\t" + "on " + item["Modified"].ToString() + "</div>" +
"<div class='ms-PostBody' >" + item["Body"].ToString() + "</div>"
);
this.Controls.Add(print);
}
}
}
Thanks in Advance