Here’s a code snippet of parsing a typical WordPress RSS feed using LINQ. Note, we have to skip the first image from the media element since that’s usually a gravatar of the author. Everything else is pretty straight forward. private void BindBlogFeed() { XDocument doc = XDocument.Load(“http://blogworkseverytime.wordpress.com/feed/”); XNamespace content = “http://purl.org/rss/1.0/modules/content/”; XNamespace media = “http://search.yahoo.com/mrss/”; [...]
Posts Tagged ‘asp.net’
Send Templated Emails Using MailDefinition Object
By J in UncategorizedRecently I discovered a better way to format my email messages in ASP.NET using the MailDefinition object. It lets you to use an email template and define tokens which you want to replace in it. This helps keep the presentation and business layers clean & seperate and lets the designers go in and edit the [...]
Code Blocks Inside Master Pages
By J in UncategorizedSome time ago I kept getting this error in one of the projects I was working on: The Controls collection cannot be modified because the control contains code blocks (i.e. ). I spent quite some time trying to figure it out. Finally after hours of searching I found out that Code Blocks Inside Master Pages [...]
Tags: asp.net, errors, masterpages
How to setup an asp.net website on localhost
By J in UncategorizedFirst lets start by setting up the site in IIS… 1.Open IIS by double-clicking on Control Panel->Administrative Tools->Internet Information Services 2.Right Click on Web Sites->Default Web Site 3.Click on Properties->Home Directory and choose the location of your website Now lets give the ASPNET account the appropriate permissions to access that directory… 4. Using My Computer [...]
How To Load & Reference An Usercontrol From Code Behind
By J in UncategorizedFirst lets create a sample user control called MyControl for demonstration purposes public partial class _Controls_MyControl : System.Web.UI.UserControl { private string _myProperty; public string MyProperty { get { return _myProperty; } set { _myProperty = value; } } protected void Page_Load(object sender, EventArgs e) { } } Now register this control in the web.config <pages> [...]
Tags: asp.net, usercontrols
ASP.NET Inline Tags
By J in UncategorizedThere are all sorts of different inline tags, and I haven’t found a place that explains them all in one place, so here is the quick and dirty… <% … %> The most basic inline tag, basically runs normal code: <% if (User.IsInRole(“admin”)) { %> You can see this <% } else { %> You [...]
Tags: asp.net
Three quick ways optimize AJAX driven websites in ASP.NET
By J in UncategorizedRecently I was involved in a project where I had to make heavy use of AJAX. I realized there are a few simple things you could do to improve performance. 1) Combine scripts <ajaxToolkit:ToolkitScriptManager ID=”TSM1″ runat=”Server” EnablePartialRendering=”true” CombineScriptsHandlerUrl=”~/CombineScriptsHandler.ashx” /> As the name of the property suggests, it will pretty much combine all the needed JS [...]
Request.Browser.Crawler
By J in UncategorizedIn my previous post about exception logging, I show how to log several different parameters related to the exception in the database. Request.Browser.Crawler is one of them and its used to track browser crawlers. It warrants its own separate entry since it requires some extra bit of setup in the web.config to get it to [...]
Exception Logging Using The Database
By J in UncategorizedThis is a simple technique I use to log exceptions in all my web applications. First lets start by adding the following to the web.config: <appSettings> <add key=”LogUnhandledExceptions” value=”true”/> </appSettings> Second, we add the following bit inside the Application_Error event of the Global.asax file. This will capture all the unhandled exceptions and log them into [...]
Tags: asp.net
The Mysterious “Invalid Parameter Used” Error
By J in UncategorizedRecently I was trying to write a little C# function for cropping images. I expected it to be a quick 5 minute task but I ended up spending a huge amount of time getting it to work correctly. I kept getting a very stubborn and mysterious error – “Invalid Parameter Used” – whenever I tried [...]