C#

Format a DateTime as a Facebook-style date with Months, Days, Hours, Minutes Ago

When you post a status update on Facebook, instead of showing you the exact date/time when you posted, the default view of Facebook is to show you the amount of minutes, hours, days, and even months since the post occurred similar to this screenshot from Facebook.

ASP.NET Programatically Add META Keywords and META Description Tags

One important part of any ASP.NET page is adding a META Keywords and META description tag to the HEAD section of the page. Many search engines place significant weight on the presence of these two tags.

There is some disagreement between SEO experts on how much weight is actually put on these tags by search engines like Google, but it is generally accepted that these tags should be present on any page that you wish search engines to index. Unfortunately, this is usually an after thought for many ASP.NET projects.

ASP.NET 301 Redirect for Search Engine Compliant Redirects

There are lots of ways in ASP.NET to redirect to a different page. When a page has been indexed by a search engine at a specific URL, you will be getting traffic from that search engine to that URL. But what if you need to move this content somewhere else or need to change the URL of the page?

ASP.NET Download File to Web Browser

Many times you will want to allow a user to click on a link on your ASP.NET page and then cause a file to be downloaded to the user. This is common for operations like exporting a file as a CSV or PDF. But if the file to download is not in a publicly / web accessible location, then it is not as simple as just putting a hyperlink to the file. Also, if you want to add security to the access of the file (such as checking for a logged in user), you will want to protect these files and they will not be able to be hyperlinked directly in your page.

C# Generate Password Hash with Salt

There are many options to store passwords in a database for authenticating users. One of the more secure methods is to store a one-way "hash" of the password instead of the password itself. Another option is to encrypt the password and store it in its encrypted form in the database. There are benefits and drawbacks to both approaches.

Password Hashing Benefits

  • If an attacker gains access to your database, they cannot retrieve the passwords of your users because they are one-way hashed (meaning that you can't back the hash back out to its original string form)