Use HostingEnvironment.MapPath

Jun 25, 2010

When running a service under IIS, the HttpContext.Current object is not available, so HttpContext.Current.Server.MapPath will fail.

fileName = HttpContext.Current.Server.MapPath(fileName);

The solution is to use Hosting.HostingEnvironment.MapPath instead.

fileName = System.Web.Hosting.HostingEnvironment.MapPath(fileName);

Custom Controls In ASP.NET

Feb 26, 2010

ASP.net has that neat little feature where all the controls can start with <asp:.  It makes it easy to code.  I had numerous custom controls and I always had to register the control on each page to use it.  Scott Guthrie had a great tip on how to register the controls in the web.config file so that it doesn’t have to be done in each page.More...

Field Codes

Jan 02, 2010

Using field codes to replace values in content, templates, and reports allows users and designers a great deal of flexibility for creating and managing content and templates without requiring code changes.

This article is a summary of how to use field codes in content, templates, or reports and how to convert them to object property values and format and replace them when displayed or rendered.  This is based on a similar pattern that Microsoft Word uses when formatting fields.  It’s also commonly used in WordPress and WordPress themes.More...

Pretty URLs And IIS6

May 12, 2009

IIS7 can support pages without extensions without administrator configuration settings. IIS6 can also support  URLs without extensions, but it requires an administrator setting. Here's a tip on how to configure IIS6 to support URLs without extensions.More...

Pretty Good URLs

Mar 13, 2009

With a little forethought and planning, it’s possible to create URLs that can be around the web for a long time and as Tim Berners-Lee pointed out cool URIs don't change.  Choose wisely though, you may have to live with the URLs for much longer than you think, or if your not careful, you may end up with too many URLs pointing to the same content. More...

How To Restart ASP.Net Applications

Feb 23, 2009

Many times, from an administration perspective, it's desirable to restart an ASP.NET web site without restarting IIS on the whole server. More...

Using Cache And Compression For Performance

Sep 24, 2008

Most browsers and servers have default values that provide fairly good performance with a minimum caching of static file content.  A little bit of coaxing can result in better performance with less traffic and less bandwidth.

There are two types of caching I discuss: static content  (*.JPG, *.JPEG, *.png, *.gif, *.ico) rarely updated and semi-static content (*.js, *.css) updated very infrequently.  The decision to cache page output (*.aspx, *.html, *.htm) long term is too dependent on application functionality decisions to discuss generically. More...