Friday, January 21, 2011

HTML and Java Script code snippets in Visual Studio 2010

We all love Visual Studio as great IDE and Microsoft is providing more and more features for that IDE. Let’s investigate one of great features that Microsoft has given with Visual Studio 2010.

What is code snippets?

Code snippets is a one of the cool feature that given in Visual Studio IDE. If you know the chunks of the code that you need to type over and over again throughout the code then this code snippets feature will help you on this. For example your exception handling code. Your redirection code everything you need more can be putted in the code snippets.

You can insert code snippets via right click –> Insert code snippets and there is also a short code is also available to bring up directly code snippets via pressing ctrl-K+ ctrl-X. Following is look of basic code snippets window.

CodeSnippets with visual studio 2010

You can put your code snippets. Below is link for creating code snippets in Visual Studio 2010.

http://msdn.microsoft.com/en-us/library/ms165394.aspx

HTML and Java Script Code snippets in Visual Studio 2010

Till visual studio 2008 the code snippets are provide only on the code behind file. But with Visual Studio 2010 now you can have that in HTML and as well Java Script code snippets also and even If you have asp.net MVC installed with Visual Studio 2010. You can have code snippets for that also.

Here you can see HTML code snippets in asp.net web form file below.

HTMLCodeSnippet in visual Studio 2010

Same way you can have it Javascript code snippets also like following.

JavascriptSnippets

Isn’t that cool? Stay tuned for more!! Happy programming.

Shout it
Share:
Thursday, January 13, 2011

HTTP Module in details

I know this post may sound like very beginner level. But I have already posted two topics regarding HTTP Handler and HTTP module and this will explain how http module works in the system. I have already posted What is the difference between HttpModule and HTTPHandler here. Same way I have posted about an HTTP Handler example here as people are still confused with it. In this post I am going to explain about HTTP Module in detail.

What is HTTP Module?

As we all know that when ASP.NET Runtimes receives any request it will execute a series of HTTP Pipeline extensible objects. HTTP Module and HTTP handler play important role in extending this HTTP Pipelines. HTTP Module are classes that will pre and post process request as they pass into HTTP Pipelines. So It’s one kind of filter we can say which will do some procession on begin request and end request.

If we have to create HTTP Module we have to implement System.Web.IHttpModule interface in our custom class. An IHTTP Module contains two method dispose where you can write your clean up code and another is Init where your can write your custom code to handle request. Here you can your event handler that will execute at the time of begin request and end request.

Let’s create an HTTP Module which will just print text in browser with every request. Here is the code for that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Experiment
{
public class MyHttpModule:IHttpModule
{
public void Dispose()
{
//add clean up code here if required
}

public void Init(HttpApplication context)
{
context.BeginRequest+=new EventHandler(context_BeginRequest);
context.EndRequest+=new EventHandler(context_EndRequest);

}
public void context_BeginRequest(object o, EventArgs args)
{
HttpApplication app = (HttpApplication)o;
if (app != null)
{
app.Response.Write("<h1>Begin Request Executed</h1>");
}
}
public void context_EndRequest(object o, EventArgs args)
{
HttpApplication app = (HttpApplication)o;
if (app != null)
{
app.Response.Write("<h1>End Request Executed</h1>");
}
}
}
}
Here in above code you can see that I have created two event handler context_Beginrequest and context_EndRequest which will execute at begin request and end request when request are processed. In this event handler I have just written a code to print text on browser.

Now In order enable this HTTP Module in HTTP pipeline we have to put a settings in web.config HTTPModules section to tell which HTTPModule is enabled. Below is code for HTTPModule.

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpModules>
<add name="MyHttpModule" type="Experiment.MyHttpModule,Experiment"/>
</httpModules>
</system.web>

</configuration>

Now I just have created a sample webform with following code in HTML like following.
<form id="form1" runat="server">
<B>test of HTTP Module</B>
</form>
Now let’s run this web form in browser and you can see here it the output as expected.

HTTPModule

Technorati Tags: ,,
Shout it
Share:

DotNetJalps Nnews- New feed address.

Hello All,

I am moving my feeds to new address so please update your feeds with my new address. Earlier there was two or three feed address and that’s why there were some confusion between the feed address among readers. So I decided to just keep one feed address for all and so I am migrating my all the feeds to following address with feed burner. There will one feed address all the things in blog. So please please update your feed address.

Following is my feed address with feed burner.

http://feeds.feedburner.com/blogspot/DotNetJalps

Still my old feed address will be available for next 30 days and then it will be deleted so please please migrate to this new feed address. 

All reader of the this blog very important because without their support It would not be possible to write blogs. So any suggestion or anything that could make my blog better is always welcome. Please read my blogs regularly and I will also try my best write my blog continuously.

I am still saying that blogging is important now days. It will increase your confidence as well in future it will be integral part of your resume. So if you are still not started blogging then start it immediately. Please read my blog post why a developer should write blog and start working on blog. Because it a shadow of your knowledge to out side world and with blogging your writing and communication skills will also improve that help you in your professional life.

Till that.. Happy programming..Stay tuned for more.

Technorati Tags: ,
Shout it
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews