Author Archive

September 1, 2008 0

How To Clear All Items From Cache

By J in Uncategorized

if (Cache.Count > 0)
{
string currentKey = string.Empty;
System.Collections.IDictionaryEnumerator cacheContents =
System.Web.HttpContext.Current.Cache.GetEnumerator();

Response.Write(string.Format(“Following {0} cache keys were cleared:”, Cache.Count));

while (cacheContents.MoveNext())
{
currentKey = cacheContents.Key.ToString();
Response.Write(currentKey + “”);
System.Web.HttpContext.Current.Cache.Remove(currentKey);
}
}
else
{
Response.Write(“Nothing to clear. Cache is empty.”);
}

Tags: ,

September 1, 2008 0

How To Load & Reference An Usercontrol From Code Behind

By J in Uncategorized

First 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 [...]

Tags: ,

June 25, 2008 5

ASP.NET Inline Tags

By J in Uncategorized

There 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 are no admin fool!
<%} %>
http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx
<%= … [...]

Tags:

May 6, 2008 0

How to easily parse HTML without RegEx

By J in Uncategorized

I recently discovered an absolutely amazing HTML parsing library for .NET called HtmlAgilityPack. It completely takes away the pain of parsing complicated HTML with regular expressions.
Here’s a very simple example of what you could do with it – I’m just extracting inner HTML from any element inside a HTML file which has a css class [...]

Tags: , ,

April 23, 2008 0

How To Create A Random Fact Generator Using XML

By J in Uncategorized

This is a simple little random fact generator which will show a new fact every time the page loads. After the initial load it will store the XML in the cache until the file is changed again.
XML: (Facts.xml)

<?xml version=”1.0″ encoding=”utf-8″ ?>
<facts>
<fact>
The numbers ‘172′ can be found on the back [...]

Tags: ,

April 22, 2008 0

How to manipulate video in .NET using ffmpeg (updated)

By J in Uncategorized

Based on the reader comments on my previous entry on this topic I was able to fix some of the issues that others were experiencing.
I changed how the output is read, instead of reading the entire stream at once, its now read line-by-line as ErrorDataReceived and OutputDataReceived events are raised. Also added an extra option [...]

Tags: ,

April 18, 2008 4

Three quick ways optimize AJAX driven websites in ASP.NET

By J in Uncategorized

Recently 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 files into one which in [...]

Tags: ,

April 8, 2008 0

Request.Browser.Crawler

By J in Uncategorized

In 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 [...]

Tags: ,

April 8, 2008 1

Exception Logging Using The Database

By J in Uncategorized

This 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 the database:

private static bool logUnhandledExceptions [...]

Tags:

March 29, 2008 0

The Mysterious “Invalid Parameter Used” Error

By J in Uncategorized

Recently 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 [...]

Tags: ,