Some must-have keyboard shortcut for VS2012

Ctrl + X : Cut selected text.
Ctrl + X : Cut current line (if there is no selection).
Ctrl + L : Cut an entire line (no need to select the line, just place the cursor at any place on that line).

Ctrl + C : Copy selected text.
Ctrl + C :  Copy an entire line  (if nothing is selected).

Ctrl + V             : Simple paste.
Ctrl + Shift + V : Paste/cycle through the clipboard ring

Ctrl + Shift + L : Delete an entire line (no need to select the line, just place the cursor at any place on that line).

Ctrl + Shift + S : Save all modified open files.

Ctrl + Shift + F : Old-styled find dialog box.

Ctrl + I : Invoke search as you type.
Ctrl + F3  : Invoke search for the current selection.

After invoking Search, you can find instances as following way-

F3 : Case-insensitive forward searches for the next instance.
Ctrl + F3 : Case-sensitive forward searches for the next instance.
Shift + F3 : Case-insensitive backward searches for the previous instance.
Ctrl + Shift + F3 : Case-sensitive backward searches for the previous instance.

Esc  :   Quit search.

Working with cursor
Ctrl + –                : Move cursor to its previous location.
Ctrl +  Shift + –   : Move cursor to its next location (if any).
Ctrl + ]                : Will take you to the matching brace. Works with all kinds of braces: ‘(‘, ‘{‘, ‘[‘. Useful for big blocks.

Insert New Blank Line
Ctrl + Enter             : Insert blank line above cursor.
Ctrl + Shift + Enter : insert blank line below cursor.

Switches among open windows
Ctrl + tab             : Move forward
Ctrl + Shift + tab : Move backward.

Toggle Full screen mode
Shift + Alt + Enter

Ctrl  : Comment selected text/current line.
Ctrl U  : Uncomment selected text/current line.
Ctrl + EC  : Comment Selected Text
Ctrl + EU  : Uncomment Selected Text

Ctrl + Space : Invoke auto complete IntelliSense.
Ctrl               : When the IntelliSense drop down is displayed, holding down Ctrl turns the list semi-transparent so you can see what is hidden behind it.

Ctrl + Shift + ]                                    : Selects code between matching parentheses.
Alt + Shift + Arrow keys(,,,)   : Select texts in a vertical block.
Alt + Mouse drag                               :   Select texts in a vertical block.

Format Code
Ctrl + K + D : Format current document.
Ctrl + K + F : Format selection
Ctrl + E + F : Format selection

Ctrl + K + K : Toggle bookmark.
Ctrl + K + P : Go to previous bookmark
Ctrl + K + N : Go to next bookmark.
Ctrl + K + L : Clear all bookmarks.

Open Tool Window
Ctrl + Alt + L           : Solution explorer
Ctrl + Alt + S           : Server explorer
Ctrl + Alt + X           : Toolbox
Ctrl + Alt + O           : Output
Alt + P + P               : Open project properties
Ctrl + WE             : Show Error List
Ctrl + Shift + C        : Class view
Ctrl + W + J             : Show Object Browser
F4                             : Properties pane.
Alt + Enter               : Properties pane.
Ctrl + ,                      : Open  ‘Navigate To’ window

Close Window
Shift + Esc : Close currently focused tool window (i.e. Solution Explorer, Toolbox etc.)
Ctrl + F4     :  Close the current document window.


F5                     : Start debugging/Move to next breakpoint.
Shift + F5          : Stop debugging.
Ctrl   + F5          : Start Without Debugging.
F10                    : Step over next statement.
F11                    : Step into next statement.
Ctrl + F10          : Run to the cursor location.
F9                       : add or remove breakpoint.
Ctrl + Shift + F9 : Delete All Breakpoints

F6                      : Build Solution
Ctrl + Shift + B : Build Solution.
Shift + F6          : Build current project.

Scrolls the window without moving the cursor
Ctrl + Up Arrow
Ctrl + Down Arrow

Toggle Between Designer/Code view
F7 and Shift+F7 to switch between designer/code view

Show Syntax/Overloads
Ctrl + Shift +Space  : Shows the syntax/overloads for the current function you are typing parameters for.

Open a file without using the mouse
Ctrl + ,  : Open  ‘Navigate To’ window.
Ctrl + Alt + A : Opens command window, type >open YourFileName.cs

Collapse/Expand Code Block
Ctrl + M + M : Toggle expand/collapse the current code block.
Ctrl + M + L  : Toggle expand/collapsed all block of code.
Ctrl + MO : Collapse to definition.

Toggle WordWrap On/Off
Ctrl + E + W :

Wrap text in a tag
Ctrl + K + S :  It is great when you want to wrap some text in a tag.  i.e. place a code block in try..catch or #region…#endregion block.


You can customize any shortcut from Tools > Customize>Keyboard button, it gives you a list of commands you can search to see if a shortcut is available, or you can select the “Press Shortcut Keys:” textbox and test shortcut keys you want to assign to see if they conflict.


Detecting Session Timeout And Redirect To Login Page In ASP.NET

This is example of Detecting Session Timeout and Redirect to Login Page in ASP.NET, session timeout occurs when user is idle for the time specified as in web.config file.

For this i’ve set time out value in web.config to 1 minute.

In web.config file, set the sessionstate mode to inproc and authentication mode to Forms

<compilation debug="true"/>
<authentication mode="Forms"/>
<sessionState mode="InProc" cookieless="false" timeout="1">

I've created three pages in this example , one is login page , when session expires , i redirect to this page , one is navigation page where i'll check if session is valid or not , if it is valid than only user will see this page other wise he gets redirected to login page.

Add Global.asax class file in root of your application or website. 
This method works only if Global.asax is present in application.

Write below mentioned code in Page_Init event of the page where we want to check for session timeout. 

we can also put this code in in a class and inherit all pages of application from this class acting as base class for all pages to check for session timeout.

protected void Page_Init(object sender, EventArgs e)
        if (Context.Session != null)
            if (Session.IsNewSession)
                HttpCookie newSessionIdCookie = Request.Cookies["ASP.NET_SessionId"];
                if (newSessionIdCookie != null)
                    string newSessionIdCookieValue = newSessionIdCookie.Value;
                    if (newSessionIdCookieValue != string.Empty)
                        // This means Session was timed Out and New Session was started

This article is part of this article.

Keyboard Shortcut for Cut & delete

Without selecting/highlighting, you can cut or delete an entire line in visual studio 2012. Just place your cursor on that line and –

1. Press Ctrl + Shift + L to delete a line

2. Presss Ctrl + L to cut a line.


Note that you can customize shortcut keys as following –

Go to Tools -> options. Tab Environment -> subtab Keyboard.

Select Edit.LineDelete. Assign a shortcut. Thats it.