Sunday, January 2, 2011

.NET Framework 4.0-Guid.Parse Method

In earlier version of .NET framework we don’t have Guid.Parse method Now we have an Guid.Parse method in .NET Framework and it’s work like any parse method. Let’s see it by an example. Let’s create console application for that.

class Program
{
static void Main(string[] args)
{
string newID = "f718943d-757d-4975-947b-3dbff1205be6";
Guid myGuId = Guid.Parse(newID);
Console.WriteLine(myGuId.ToString());
Console.ReadLine();


}
}
and as expected here is the out put for that.

Guid

That’s is it’s cool. Stay tuned for more..Happy programming..
Technorati Tags: ,
Shout it
Share:

Creating an HttpHandler to handle request of your own extension

I have already posted about http handler in details before some time here. Now let’s create an http handler which will handle my custom extension. For that we need to create a http handlers class which will implement Ihttphandler. As we are implementing IHttpHandler we need to implement one method called process request and another one is isReusable property. The process request function will handle all the request of my custom extension.

so Here is the code for my http handler class.

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

namespace Experiement
{
public class MyExtensionHandler:IHttpHandler
{
public MyExtensionHandler()
{
//Implement intialization here
}

bool IHttpHandler.IsReusable
{
get { return true; }
}

void IHttpHandler.ProcessRequest(HttpContext context)
{
string excuttablepath = context.Request.AppRelativeCurrentExecutionFilePath;

if (excuttablepath.Contains("HelloWorld.dotnetjalps"))
{
Page page = new HelloWorld();
page.AppRelativeVirtualPath = context.Request.AppRelativeCurrentExecutionFilePath;
page.ProcessRequest(context);

}
}
}
}
Here in above code you can see that in process request function I am getting current executable path and then I am processing that page.

Now Lets create a page with extension .dotnetjalps and then we will process this page with above created http handler. so let’s create it.

Creating your own extension

It will create a page like following.

Extension

Now let’s write some thing in page load Event like following.


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

namespace Experiement
{
public partial class HelloWorld : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Hello World");
}
}
}

Now we have to tell our web server that we want to process request from this .dotnetjalps extension through our custom http handler for that we need to add a tag in httphandler sections of web.config like following.

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add verb="*" path="*.dotnetjalps" type="Experiement.MyExtensionHandler,Experiement"/>
</httpHandlers>
</system.web>
</configuration>
That’s it now run that page into browser and it will execute like following in browser

Browser

That’s you.. Isn’t it cool.. Stay tuned for more.. Happy programming..
Technorati Tags: ,,
Shout it
Share:

Thanks All the readers and community and Happy new year to all of you.

This is my first blog post for new year 2011 and I would like to take this opportunity to thank all the readers for making my blog very successful and accepting me a community member. As year 2010 has lots of up down in IT filed it was recession period and now we almost recovered from it.

Personally year 2010 has been very successful to me as I have been awarded as Microsoft Most Valuable Professional for visual C#. And It was one of the greatest achievement of my life. I would like to take this opportunity to thanks Microsoft for this and thanks all friends specially Jacob Sebastian who has given me guidance any time I required it.

I have been also awarded dzone most valuable blogger this year and it was a nice surprise from dzone. I would like thanks dzone for this.

Once again I am wishing you happy new year and may this year will bring success to all of you. One more thing I have found that I have met lots of people who is quite intelligent and exceptional developers and IT professionals but they are not blogging their stuff. I would say please my blog post a why a developer should write blog and Start blogging immediately because unless and until you don’t blog community will not know what you are doing. 

Till then happy blogging and programming ... Stay tuned for more..

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