Tuesday, July 13, 2010

Reverse lookup Asp-Routing

When we use asp routing, it is easy to get the routed path from current request. 

var routedPath = HttpContext.Current.Request.Path;

But how to get the original path is a bit tricky. Here, how you do it.

var originalPath=   ((PageRouteHandler) System.Web.HttpContext.Current.Request.RequestContext.RouteData.RouteHandler).VirtualPath;

Tuesday, February 16, 2010

Simple task Scheduling using Global.asax

The article below describes very simple task scheduling by just using Global.asax.

http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax

However, I had changed the approach slightly because I didn't  want to rely on Session_Start() event and execute my code unnecessarily. Below you find another simple example with Timer control.

private static Timer ScheduledTaskTimer = new Timer();

void Application_Start(object sender, EventArgs e){

      ScheduledTaskTimer.Elapsed += new ElapsedEventHandler(ScheduledTaskTimer_Elapsed);

       ScheduledTaskTimer.Interval = 1 * 60 * 60 * 24;

    ScheduledTaskTimer.Enabled = true;

}

static void ScheduledTaskTimer_Elapsed(object sender, ElapsedEventArgs e)

        {

            //your scheduled task logic goes here.

        }

Technorati Tags: ,,,