Site: http://madskristensen.net/ Link: http://feeds.feedburner.com/netslave
by via .NET Slave on 12/8/2011 5:40:41 PM
Writing correct CSS can sometimes feel a little frustrating – especially with all the vendor specific properties and cross-browser techniques we need to be aware of. CSSCop for Visual Studio tries to help us write better CSS, by making sure we remember all the right vendor specific properties or that you cannot set the margin on inline HTML elements etc. CSSCop uses the best CSS linting tool available today – CSS Lint. Like FxCop will frustrate you the first time you run it, so promises CSS L ...
[ read more ]
by via .NET Slave on 6/15/2011 5:48:00 PM
We just released the first Web Standards Update for Microsoft Visual Studio 2010 SP1. Despite its name, the update also works for Visual Web Developer Express 2010 SP1. You can read more on our team blog. In this first release of the update, we have focused on bringing the HTML5 support up-to-date, adding CSS 3 support and bring more new API’s to the JavaScript intellisense. The plan is to make a release on a regular schedule to keep Visual Studio updated with the changes made by W3C. HT ...
by via .NET Slave on 1/27/2011 2:54:00 PM
Since the release of Visual Studio 2010 SP1 beta last month, there has been a lot of questions regarding the support for HTML5 and CSS3. HTML5 Visual Studio 2010 was originally released without HTML5 support, so does SP1 finally add support for it? Yes, to some extent. The entire HTML5 specification isn’t supported but most of the new elements and attributes are. That means you get both intellisense and validation for HTML5 with SP1. Turn it on After installing SP1 you have to tell Visual ...
by via .NET Slave on 12/1/2010 7:38:16 PM
HTML5 and CSS3 introduces some new file types that enables us to create even better websites. We are now able to embed video, audio and custom fonts natively to any web page. Some of these file types are relatively new and not supported by the IIS web server by default. It’s file types like .m4v, .webm and .woff. When a request is made to the IIS for these unsupported file types, we are met with the following error message: HTTP Error 404.3 - Not Found The page you are requesting cannot be se ...
by Mads Kristensen via .NET Slave on 2/28/2010 8:00:00 PM
A few weeks back i found out that the method I use to minify CSS was about 5% more efficient than the YUI Compressor. I tweeted about it and was encouraged to post the code that does the actual minification. public static string RemoveWhiteSpaceFromStylesheets(string body) { body = Regex.Replace(body, @"[a-zA-Z]+#", "#"); body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty); body = Regex.Replace(body, @"\s+", " "); body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$ ...
by Mads Kristensen via .NET Slave on 11/8/2009 3:26:00 PM
A few days ago, Google released their Closure Compiler project for optimizing JavaScript. Here’s what they write about the Closure Compiler: The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. The interesting part of the ...
by Mads Kristensen via .NET Slave on 10/28/2009 11:10:00 PM
In the past few days, I’ve worked on finding a way to do static code analysis on JavaScript files.The resaon is that I want to apply some sort of binary and source code checking like FxCop and StyleCop provides for C#. There exist some tools for linting JavaScript like JavaScript Lint, but linting only checks syntax and not implementation. To do that I found the Jscript compiler build into the .NET Framework to be just what I wanted. It compiles JavaScript and reports if it finds any error ...
by Mads Kristensen via .NET Slave on 5/21/2009 12:30:00 PM
I’ve been working lately with some ASP.NET performance optimization automation HTTP modules. In one of them I needed to know if the last-modified header had been set through the Response.Cache.SetLastModified(DateTime) method. For some reason, there is no API available anywhere within the BCL to retrieve the last modified date of a response – you can only set it. Since the module wouldn’t work without a way to read the last modified date of the response, I had to use Reflector ...
by Mads Kristensen via .NET Slave on 2/8/2009 4:59:00 PM
Last Wednesday I gave a presentation about performance optimization techniques in ASP.NET. In the demo I used a class called WebOptimizer that I’ve written specifically for that presentation, but based on techniques and code I’ve been using for years. The static WebOptimizer class contains a few public helper methods that allow any web project to do HTTP compression, removal of whitespace from HTML, CSS and JavaScript, and support for conditional GET requests. After the presentation ...
by Mads Kristensen via .NET Slave on 1/22/2009 8:43:00 PM
A couple of weeks ago I released an online TV guide for Danish viewers called ifjernsyn.dk. The goal was to make a very simple overview that could easily be accessed from a mobile phone and customized by any visitor without any login. The purpose was to always know what’s on the air right now and what programs will shortly follow – and of course to keep it simple. Since the release, some people have asked me about how I did some of the things and one of the most frequently asked ques ...
by Mads Kristensen via .NET Slave on 11/19/2008 8:42:00 PM
Google’s maps API now supports reversed GEO lookup which allows you to find an address based on geo coordinates. All you need is a latitude, a longitude and this handy method: private const string endPoint = "http://maps.google.com/maps/geo?q={0},{1}&output=xml&sensor=true&key=YOURKEY"; private static string GetAddress(double latitude, double longitude) { string lat = latitude.ToString(CultureInfo.InvariantCulture); string ...
by Mads Kristensen via .NET Slave on 11/2/2008 1:45:00 PM
About 10 years ago, it was actually possible to look people up by their e-mail address online. You could also find a persons e-mail by searching for his or her name. Back then there where a lot of e-mail directories that acted like the yellow pages but for e-mail addresses. Very handy, but when spam became a problem, no one was willing to publicise their e-mail address and the e-mail search quickly died out. Years passed and nobody thinks seriously about searching for people by their e-mail addr ...
by Mads Kristensen via .NET Slave on 10/30/2008 8:53:00 PM
I’ve been thinking about how to solve a very simple problem on a website: visitor behaviour tracking. In a sense it is what Google Analytics does, but there are problems with conventional JavaScript based trackers. They are good at tracking page views, but very bad at tracking actions or behaviour around a website. Some products like Headlight are actually pretty good at tracking actions such as button clicks etc, but at the level I’m interested in tracking, I would have to add JavaS ...
by mkk.nospam@nospam.easywebdesign.dk (Mads Kristensen) via .NET Slave on 4/23/2008 11:48:00 PM
I’ve been looking deeply into FOAF lately and last week I worked on a parser that could wrap a FOAF document into a strongly typed class for easy consumption by C#. Now I want to share it with anyone interested. It appears there are no FOAF parsers available in C# yet. I wasn’t able to find any. The parser The class FoafParser has two public methods, Parse and ParseFriendsAsync, which handles two different approaches in fetching FOAF documents. The Parse method This method tak ...
by mkk.nospam@nospam.easywebdesign.dk (Mads Kristensen) via .NET Slave on 12/18/2007 10:50:00 PM
For so many years I’ve written code that needed to know whether or not a collection of objects has been changed or not. Now I’ve finally written the code that tells me just that. The scenario is typical. You have a class called Order with a property called OrderLines which is a generic List containing OrderLine objects. You retrieve the Order class from the database including all the OrderLines, change some properties and then you save the Order object back to the database. ...
by Mads Kristensen via .NET Slave on 12/12/2007 6:06:00 PM
My last post about comment spam fighting resulted in a lot of e-mails from readers asking how to create their own spam fighting logic in BlogEngine.NET 1.3. So I decided to show a simple extension that listens for certain bad words and filters on those. If a comment contains one of the predefined words it is considered spam. The extension [Extension("Filters comments containing bad words", "1.0", "Mads Kristensen")] public class BadWordFilter { ...
by Mads Kristensen via .NET Slave on 9/13/2007 7:20:00 PM
Recently I’ve needed a method that would look at some text and automatically discover all URLs and turn them into hyperlinks. I’ve done that before so it was a matter of copy/paste. This time it was a little more complicated, because the resolved URLs could not be longer than 50 characters long. That was important because otherwise it would break the design. A long URL doesn’t word wrap so it would end up bleeding out of the design. So, the challenge was to resolve the URLs ...
by Mads Kristensen via .NET Slave on 8/1/2007 4:17:00 PM
Many blogs have the ability to ping different ping-services, such as Ping-o-Matic, Feedburner and Technorati, whenever some content is created or updated. But it is not only blogs who can benefit from pinging these services. Almost all websites that is updated regularly can use this technique. All these services use XML-RPC and the exact same format, so you can write a ping class ones and then just add whatever ping service URL later. I’ve written a very simple static ping class that c ...
by via .NET Slave on 7/9/2007 3:42:00 PM
I was asked to write a post about my views on unit testing because it is a hot subject at the moment. I’m very ambivalent about unit testing and always have been for many different reasons. Although testing is very important, I often find unit testing to be a time consuming liability but it depends on the project. Good for static classes Over the years I’ve build many helper class libraries which is used in many projects and can be considered as business independent fundamental ...
by via .NET Slave on 6/18/2007 9:34:00 PM
I’ve always been a little annoyed by the fact that ASP.NET websites sends the version number as a HTTP header. For an ASP.NET 2.0 application this is added automatically to the headers and you cannot remove it from code. This is what it looks like: X-AspNet-Version => 2.0.50727 Why would it be necessary to send this information about your application to possible hackers? It doesn’t make sense. Maybe it’s because it allows for statistics to be collected about what v ...
by via .NET Slave on 6/17/2007 4:54:00 PM
I’ve always been a big fan of using the ThreadPool for asynchronous execution, but in ASP.NET it is not the best approach for multi-threading. I’m not writing about when threading is appropriate and the impact of multi-core or dual core machines when doing threading, but point out that the ThreadPool is not the best choice for ASP.NET applications. ThreadPool is easy The reason why I like the ThreadPool is because it is managed for me and it is very easy to use and it only takes ...
by via .NET Slave on 5/27/2007 6:11:00 PM
Some people have asked me how BlogEngine.NET displays a dropdown list of countries when no source XML file is present. The simple answer is that you don’t need any external list to bind to from C#, you can instead use the CultureInfo class. Consider that you have the following dropdown list declared in an ASP.NET page: <asp:DropDownList runat="server" ID="ddlCountry" /> Then from code-behind, call this method which binds the countries alphabetically to th ...
by via .NET Slave on 5/16/2007 8:04:00 PM
Some time ago, when I wrote the blog post importer for BlogEngine.NET, I wanted to be able to display different text in the ClickOnce application dependant on the user opening it directly from a web page. I did some digging and found out that ClickOnce supports query strings just like a website. That made it possible to create a link similar to this: BlogConverter.application?url=http://blog.madskristensen.dk/&username=my username Enable URL parameters In your ClickOnce project, ri ...
by via .NET Slave on 5/10/2007 12:00:00 AM
In some situations it can be important to know which methods are calling other methods. Think of an error log. Here you would like to know which method that threw the error and at what line in what file. This helps to debug runtime code and makes it very easy to find the exact point of failure. C# 2.0 has the possibility to go back in time and inspect which methods called other methods all the way up the stack. Here is a static method that does just that and returns the caller of any method ...
by via .NET Slave on 4/28/2007 12:00:00 AM
I know, it sounds silly but hear me out. In March 2006 I wrote a post about the use of Word as a text editor for writing blog posts, because it would be the natural place to do so. At that time Office 2007 was in beta 1 if I remember correctly and Word did not have the functionality to do blog posts at that point. I wrote a mail to Microsoft suggesting that it would be a cool feature to include in Word 2007. They never wrote back. A couple of months later, Office 2007 beta 2 was released and ...
by via .NET Slave on 4/22/2007 12:00:00 AM
Some of you might know by now that simplicity is the most important development metric for me. That’s because I have seen so many times what can happen to complex code and it isn’t nice. Complex code is harder to understand, difficult to maintain, nearly impossible to extend and downright ugly. Complexity Some developers tend to over-complicate a task and ends up writing too many classes to solve a simple problem. The ability to take a step back and observe the problem space befo ...
by via .NET Slave on 4/9/2007 8:06:36 PM
If you have a broken internal link on your ASP.NET website and follow it, you will see the well known yellow screen of death (YSOD). Not only is it ugly, but it could also tell the visitor more than they should know about your system. The broken link sends a 404 HTTP status code to the client, but instead of providing the visitor with the YSOD, it will be better to use the browsers build-in view for those kinds of errors. It’s a view visitors know and not an arbitrary YSOD with strange informati ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 4/2/2007 8:37:52 AM
Many websites have started to add a little icon next to external links, so that visitors know that if they follow it, they will leave the website. Here is a small JavaScript that adds a class called external to all off-site links on the page. Just call the function when the page has loaded. // Sets a class to all external links function StyleExternalLinks() { var divs = document.getEl ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/25/2007 6:13:10 PM
Gravatar icons can be used on all websites that lets users write comments. It could be in a forum or on a blog. The image is retrieved from the Gravatar website and is based on the e-mail address of the person that makes the comment. It is very easy to set up because it is just a normal image where the src attribute point to the Gravatar website. Here is a method that writes out such an image. It takes an e-mail address and a ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/15/2007 4:17:33 PM
As a follow-up on my post from yesterday about generating shorter GUIDs, I’ve created a small helper class in C#. The class encodes a GUID into a 22 character long string and decodes the string back to the original GUID again. That way you can save 10 characters from the original GUID and it is ASCII encoded so it will work perfectly in a URL as a query string or in ViewState. It takes a standard GUID like this: ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/14/2007 9:19:07 PM
The System.Guid is used whenever we need to generate a unique key, but it is very long. That’s in many cases not an issue, but in a web scenario where it is part of the URL we need to use its string representation which is 36 characters long. It clutters up the URL and is just basically ugly. It is not possible to shorten it without loosing some of the uniqueness of the GUID, but we can come a long way if we can accept a 16 charact ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/13/2007 8:20:51 PM
I’ve noticed that there are two different ways developers locate private variables used by properties. One way is to locate the private variable next to the property that returns them and all other private variable located elsewhere. #region Private fieldsprivatestring _Member;privateint _AnotherMember;#endregion#region Propertiesprivatestring _Name;publicstring Name { get { return _Name; } set { _Na ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/9/2007 10:55:24 PM
A web page with a data bound GridView control can take a long time to load. The page is not rendered until all the controls are, and the GridView cannot render before data has been retrieved from the database. So, let’s load the GridView asynchronous and make the page load faster and the perceived speed greater. This little trick is actually very simple and it involves the built-in client callback feature of ASP.NET. Even though I’ ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/7/2007 11:25:35 PM
A couple of days ago, I had to store some very big strings in an XML file. To keep the file size down I wanted to compress the strings using a GZipStream and then decompress them later when needed. I modified the methods from Papenoo pa so they handled strings in stead of byte arrays. using System.IO.Compression;using System.Text;using System.IO;publicstaticstring Compress(string text) { byte[] buf ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/6/2007 8:26:01 PM
The blogroll has become a standard element on most blogs today. If it is an ASP.NET blog, the blogroll probably contains links to other ASP.NET blogs and that gives the visitor an opportunity to surf to other related websites. The only problem with it is that you have no idea what to expect from the blogs by looking at the blogroll. Most often, the link title on the blogroll contains the name of the author and if you don’t know him/her on beforehand, yo ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 3/1/2007 8:02:56 PM
On a small test website I’m building in my spare time, I wanted a way to count the number of clicks to the outgoing links from that site. Imaging hosting banners or other affiliate links where you get paid per click, it would be nice to know how many have clicked on them instead of relying on the advertiser’s own statistics. There are third-party products that can do it, but I would like to keep that data myself and it would be fun to build at the same ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/26/2007 5:27:47 PM
At work, we are about to build a new internal tool for administration of different systems. We developers need certain applications and the sales department needs some other ones. All the different people need to be able to administrate different systems, so we decided to create one application that hosts only the applications the individual needs. Last weekend I played with a generic application that hosts other applications by u ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/25/2007 11:21:23 PM
Today, I needed to store images in XML files so I had to serialize an image file into text so it could be written in the XML file. Of course, it should also be deserialized back to an image again by reading from the XML file. The result is the following two methods. The first method serializes a file on disk and returns the base64 string representation. public static string Serial ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/20/2007 8:19:20 PM
A week ago I wrote about the native client callback feature of ASP.NET 2.0 and why it isn’t always the smart choice. That post got me some good feedback that inspired me to build a custom callback implementation so you wouldn’t have to use the native one. I could just use other AJAX libraries such as ASP.NET AJAX or Ajax.NET, but that’s not fun. When I started thinking about this little project I imagined it to be complex, but actually it turned out to be extremely si ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/13/2007 5:14:25 PM
Some say that screen scraping is a lost art because it is no longer an advanced discipline. That may be right, but there are different ways of doing it. Here are some different ways that all are perfectly acceptable, but can be used for various different purposes. Old school It’s old school because this approach has existed since .NET 1.0. It is highly flexible and lets you make the request asynchronously. ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/8/2007 10:53:07 PM
Update February 11th. The class now updates every feed in the cache asynchronously and automatically. On the login screen of Headlight, we are soon adding news updates so that our customers can see what is going on with the product. The content is delivered from our company blog via RSS and we are probably going to use FeedBurner’s JavaScript to display the latest items. Then I started thinking about how easy it would be to wri ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/6/2007 11:41:07 PM
Over the years, I’ve used a lot of third-party components and self built control libraries. It an easy way to add functionality to your code projects – just reference the dll file and that’s it. This encapsulated functionality comes in most cases at a high cost. Not in price and performance, but in customization. Imaging that you have an assembly of your homemade ASP.NET controls that you wish to use in your new websi ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/6/2007 8:00:32 PM
Here is a complete list of all the classes available for download on this website. The links points to the blog post, so you can get explanations on how to implement them and examples on how to use them. It is also a good idea to read the comments for any tips or alternate uses. They are all written in C#, but if you want them in VB.NET you can use this online C# to VB.NET converter tool. Classes Sto ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/6/2007 7:48:07 PM
Here is a list of the different tools I've developed and posted to this website. Source code in C# is included for all tools. The links points to the blog post, so you can get explanations and examples on how to use them. The tools are not covered by any licenses, so you can do with them what you want and modify them as much as you like. Search Engine Positioner The application let you save the keywor ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/6/2007 7:32:49 PM
Here is a complete list of all the HttpModules and HttpHandlers on this website. The links points to the blog post, so you can get explanations on how to implement them and examples on how to use them. It is also a good idea to read the comments for any tips or alternate uses. They are all written in C#, but if you want them in VB.NET you can use this online C# to VB.NET converter tool. HttpModules A ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/4/2007 1:52:40 PM
Many websites have two points of entry for each individual page – one with www and one without. It means that if other websites link to yours, they might link to the same page using two different addresses. If you make sure that all incoming links point to the same address, you also make sure that various page ranking algorithms of the different search engines give the page full credit for each incoming link. We can ac ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/3/2007 11:21:28 PM
After I wrote about how to check a website's position at the Google search result page, I thought it would be fun to write a little application that uses that method, but extend it to work with Yahoo and AltaVista as well. This is the result. The application let you save the keywords of all the websites you want to check. Then just press the “Find positions” button and it automatically retrieves the data fr ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 2/3/2007 8:17:11 PM
One of the biggest problems with the different types of collections in the .NET Framework, is that they don’t tell you if the collection as been changed or not. If you have a Collection<int> that has to be persisted to a database, it would be a waste of resources to do so if the collection hasn’t been changed. That’s why I found it necessary to override the generic Collection<> class to provide it with a property called IsCha ...
by post@madskristensen.dk (Mads Kristensen) via .NET Slave on 1/31/2007 7:09:13 PM
If you want to test your position in Google for a certain search term, you can do so by using the Google website. By position I don't mean Page Rank, but the actual place in the search results. You can also use C# to find the position like the method shows below. You can use the code to build a cool application that lists the positions of your website based on all your important search terms. You can change it to run asynchronously ...
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.