If you haven't been programming in visual studio for long, chances are you haven't heard about code snippets.
Code snippet is actually code which you can quickly insert into the code editor. Typically snippets are common language constructs which you use often and a number of them come bundled with VIsual Studio. You probably noticed them in IntelliSense as you were typing code.
As the tooltip says, you can simply go to code snippet and then hit TAB key twice to insert it.
Some useful C# snippets are:
- #region - Inserts #region and #endregion, puts a cursor where you would normally type the name.
- try - Inserts a try-catch
- tryf - Inserts a try-finally
- for and forr - Insert for and reverse for loops
- prop - Inserts an automatic property
- propfull - Inserts a property and a backing field
As snippets for these short constructs exist, there are also snippets for entire classes and methods. And you can also create your own. To see all snippets that are shipped with Visual Studio, simply go to Tools -> Code Snippets Manager...
This nifty little thing is also available in Visual Studio Community Edition. You can play with the snippets, download new ones from the Internet and if you try to get into a habit of using them, possibly even improve your coding practices.
In a future blog post we'll create a small code snippet of our own.
In this blog post we'll talk about URL Rewriting and how it can be done using Microsoft's IIS. Why IIS? Because there are not that many tutorials that cover that stuff. Also, some very experienced PHP developers don't know how to rewrite URLs if their page is hosted on IIS.
URL Rewriting basically means: altering the URL's apperance without affecting behaviour of your site. But why would someone alter the apperance of an URL?
Well, there are couple of great reasons. First, of course is Search Engine Optimization (SEO). For example, compare the following URL:
With this one:
What are the advantages of URL number two? It's friendlier to both users and search engines. Users can immediately tell what the blog post is about and it also helps your site to get better search engine rankings.