Finding the execution time of a action in mvc 3 using global action filters

Posted by Unknown 0 comments
Finding the execution time of a action in MVC 3 using global action filters.

Today i found a very interesting issue while working with global action filters in MVC,we can measure the execution time of the  action with the help of "OnResultExecuting" and "OnResultExecuted" method in the action filter attribute.

Here we can track the user activities and logs globally in global action filter attribute.So each and every request can be captured in action filter attribute.

Here is the step by step explanation of how to implement global action filter with example of measuring excution time of a action.

public class StopwatchAttribute : ActionFilterAttribute
{
    private readonly Stopwatch _stopwatch;
 
    public StopwatchAttribute()
    {
        _stopwatch = new Stopwatch();
    }
 
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        _stopwatch.Start();
    }
 
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        _stopwatch.Stop();
 
        var httpContext = filterContext.HttpContext;
        var response = httpContext.Response;
        var elapsed = _stopwatch.Elapsed.ToString();
 
        // Works for Cassini and IIS
        //response.Write(string.Format("<!-- X-Stopwatch: {0} -->", elapsed));  
 
        // Works for IIS
        response.AddHeader("X-Stopwatch", elapsed);
    }
}  



Now register these filter in gloabal.asax aplication_Start

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
 
    GlobalFilters.Filters.Add(new StopwatchAttribute());
 
    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
}


Now create the controller with a sample action 


public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewModel.Message = "Welcome to ASP.NET MVC!";
 
        return View();
    }
 
    public ActionResult About()
    {
        return View();
    }
}



Now run your mvc application, when action executing it will starts the timer on 
"OnActionExecuting" and stops the timmer in "OnActionExecuted".and displays the 
execution time in responce header or if you can write it in responce.write like 
below.

Output of StopwatchAttribute



Here if you want too track or log the user activities you can use



public class UserActivityAttribute : ActionFilterAttribute
{
  public override void OnResultExecuting(ResultExecutingContext filterContext)
  {
    if ((filterContext.Result is RedirectToRouteResult) &&
        (filterContext.RequestContext.HttpContext.Request.RequestType == "POST"))
    {
      var originController = filterContext.RouteData.Values["controller"].ToString();
      var originAction = filterContext.RouteData.Values["action"].ToString();
 
      if (originAction == "Create")
      {
 
      }
    }
    base.OnResultExecuting(filterContext);
  }
}
Hope this will helpl you
Labels: ,

Free jquery plug in for modal popup,tab control,slider,validations

Posted by Unknown 0 comments
Free jquery plug in for modal popup,tab control,slider,validations

Today i found a very usefull free jquery plug in while googling.i.eqTip2 jquery plug in
Here we have preprocessed jquery plug in for modal popups,tab control,slide and form validation

Click here to see the demo and download


Labels:

Getting a MIME type from a file extension in ASP.NET 4.5

Posted by Unknown 0 comments

Getting a MIME type from a file extension in ASP.NET 4.5


if you are worked with MIME type file upload and download in ASP.NET,you have come across the situation of providing the  mime type from file extension.In general to provide mime type  file extension   we might have to maintain dictionary of mime type or need to write switch case of to accomplish this.


In asp .net 4.5 we have very good feature to provide  MIME type of file extension  by using the 
 System.Web.MimeMapping.In the api we need to use single line of call GetMimeMapping(string fileName)

Here is the documentation from the msdn MSDN documentation

Hope this will helps you.
Labels:

Microsoft Dynamics CRM 2011 Custom Code Validation Tool Released

Posted by Unknown 0 comments
Microsoft Dynamics CRM 2011 Custom Code Validation Tool Released

Download link Microsoft Dynamics CRM 2011 Custom Code Validation Tool

To resolve breaking script issues in CRM microsoft released custom code validation tool which is very help full to find  script issues in in your forms.
This is tool is provided as managed solution which can be imported in microsoft dynamics crm 2011

To install the solution follow the bellow steps

1.      Launch Microsoft Dynamics CRM using Internet Explorer with a user account that has privileges to import solutions.
2.      Log into the Microsoft Dynamics CRM organization that you want to install the solution.
3.      Click the Settings area in the left hand navigation pane in Microsoft Dynamics CRM 2011.
4.      Click the Solutions navigation item under the Customizations sub-area in the left hand navigation pane.
5.      Click the Import button on the toolbar for the All Solutions grid view.
6.      Click the Browse button and select the folder where the CustomCodeValidationToolForMicrosoftDynamicsCRM201_1_0_0_0_managed.zip file is located.
7.      Click the Next button and proceed to import the solution.
8.      Once the import completes, click the Close button to close the Import Solution dialog.
9.      Click the Publish All Customizations toolbar button on the All Solutions grid view to publish the solution.
10.   To launch the tool, double click on the CustomCodeValidationTool solution to open it.

11.   Click the Open the Custom Code Validation Tool button on the solution’s Configuration Page to launch the tool.

Hope this will helps
Labels:

Asp.net MVC client side model validations step by step

Posted by Unknown 0 comments
Asp.net MVC client side model validations

In this post am going to explain you about client side model validations in asp.net MVC
in MVC 2.0 or avove versions  we have bunch of features that we can enable many features at client side
in that one of the most important and useful was model validation at client side with help of unobtrusive validation jquery.

with this unobtrusive jquery we can do the validations based on the data annotations which are applied on the model classes.

In order to enable client side model validation we need a two jquery references see the image bellow 

in MVC 2.0 we need to add these two references 

image

If you are in MVC 3.0 or avove use
                       "~/Scripts/jquery.unobtrusive.js",
                        "~/Scripts/jquery.validate.js"

here is the step by step implementation for client side model validation see bellow


image



















image




image



image



image



image




image

image

image




image


hope this will helps you


Labels: ,

how to add images from file location WPF

Posted by Unknown 0 comments
how to add images from file location WPF

In WPF development working with the images most of the new developers to WPF they struck at the loading the images from the file location.There is a simple way to accomplish to this.
 

Simply we can use

image1.Source = new BitmapImage(new Uri(filePath));


Here you can use the filepath with help of new uri class. 
Labels:
 
test