Server Utility Functions for Non-Web Apps
This is just a quick post. Normally, when one needs to use such functions as HtmlEncode, HtmlDecode, UrlEncode, UrlDecode and related functions, one would normally go to the Server class in your current HttpContext.
However, in the case that you're running in a console application for any particular reason, you don't have an HttpContext.Current, and you would then throw a "Object reference not set to an instance of an object" (aka Null Reference Exception).
The correct way to do this is to use the System.Web.HttpUtility class. This utility is the one used internally by the Server object.
Recent blog posts
- Canned VirtualPC Instances for IE 6, 7, 8 on XP/Vista
- Checking assembly dependencies for .NET
- Google's Public DNS
- Server Utility Functions for Non-Web Apps
- reCAPTCHA for ASP.NET MVC that uses ModelState
- Adding a container to ValidationSummary helper in ASP.NET MVC
- Generic XML Serialization Class
- Re-throwing Exceptions in C# with InternalPreserveStackTrace
- Solving xsd generation error: 'The element .... is missing'
- Enum DropDownList in ASP.NET MVC
Recent comments
9 weeks 2 days ago
12 weeks 3 days ago
15 weeks 4 days ago
21 weeks 2 days ago
31 weeks 1 day ago
1 year 15 weeks ago
1 year 32 weeks ago
1 year 33 weeks ago
1 year 39 weeks ago
2 years 16 weeks ago