Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Most frequently asked oops interview questions

Posted by Unknown 0 comments
Most frequently asked oops interview questions

                   In this post am going tell you about most frequently asked oops interview questions,In previous post i have explained  Most frequently asked interview questions in mvc Please read below about Oops questions


  1. What is object-oriented programming (OOP)?
  2. What is class? Give a real life example
  3. What is an object? Give a real life example.
  4. Explain the basic features of OOPs
  5. What is the relationship between a class and an object?
  6. What is difference between OOP and procedural Language?
  7. What is encapsulation? Why encapsulation is necessary, explain with example?
  8. Tell about access modifier
  9. What is value type and reference type, explain with example?
  10. What is polymorphism, explain with example?
  11. What is run time polymorphism, explain with example?
  12. How is method overriding different from method overloading?
  13. What is inheritance, explain with example?
  14. What is interface? Why interface is used?
  15. What is abstract class? Why abstract class is used?
  16. What is static member? Why static member? How static member is accessed?
  17. Can you specify the accessibility modifier for methods inside the interface?
  18. What is constructor? Why constructor is used?
  19. What is constructor overloading?
  20. Is it possible for a class to inherit the constructor of its base class?
  21. What is the difference between arrays and collection?
  22. What are collections and generics?
  23. How can you prevent your class to be inherited further?
  24. What is the index value of the first element in an array?


Hope this will helpful
Labels:

ASP.NET 4.5 ScriptManager features

Posted by Unknown 0 comments

ASP.NET 4.5 ScriptManager features:

                   In asp .net web development script manager control playing a key role,we are seeing lot features being added to this control since from last couple of frame work up gradations.in latest asp net 4.5 Microsoft added  some key features to this control like 

  •  Easy integration with J query
  • Debug and release support
  • CDN Supprot
  • LoadSuccessExpression
  • Override Script Mappings
  • Remapping Framework scripts
  • Serving Framework Scripts from inside the application
Find the below some of code snippets to implement new features of script manger 

JQuery

string str = "1.7.1";
    ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
    {
        Path = "~/Scripts/jquery-" + str + ".min.js", 
        DebugPath = "~/Scripts/jquery-" + str + ".js", 
        CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + str + ".min.js", 
        CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + str + ".js", 
        CdnSupportsSecureConnection = true, 
        LoadSuccessExpression = "window.jQuery"
    });

JQuery.UI

string str = "1.8.20";
    ScriptManager.ScriptResourceMapping.AddDefinition("jquery.ui.combined", new ScriptResourceDefinition
    {
        Path = "~/Scripts/jquery-ui-" + str + ".min.js", 
        DebugPath = "~/Scripts/jquery-ui-" + str + ".js", 
        CdnPath = "http://ajax.aspnetcdn.com/ajax/jquery.ui/" + str + "/jquery-ui.min.js", 
        CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jquery.ui/" + str + "/jquery-ui.js", 
        CdnSupportsSecureConnection = true
    });

These SciptMappings are registered with ScriptManager as follows
<asp:ScriptManager runat="server">
        <Scripts>
            <asp:ScriptReference Name="jquery" />
            <asp:ScriptReference Name="jquery.ui.combined" />            
        </Scripts>
    </asp:ScriptManager>


<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.1.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
(window.jQuery)||document.write('<script type="text/javascript" src="Scripts/jquery-1.8.1.js"><\/script>');//]]>
</script>
 We are registering all the scripts and we are bundling them together as “MsAjaxBundle”
ScriptManager.ScriptResourceMapping.AddDefinition("MsAjaxBundle", new ScriptResourceDefinition
    {
        Path = "~/bundles/MsAjaxJs", 
        CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/MsAjaxBundle.js", 
        LoadSuccessExpression = "window.Sys", 
        CdnSupportsSecureConnection = true
    });
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjax.js", "window.Sys && Sys._Application && Sys.Observer");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxCore.js", "window.Type && Sys.Observer");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxGlobalization.js", "window.Sys && Sys.CultureInfo");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxSerialization.js", "window.Sys && Sys.Serialization");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxComponentModel.js", "window.Sys && Sys.CommandEventArgs");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxNetwork.js", "window.Sys && Sys.Net && Sys.Net.WebRequestExecutor");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxHistory.js", "window.Sys && Sys.HistoryEventArgs");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxWebServices.js", "window.Sys && Sys.Net && Sys.Net.WebServiceProxy");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxTimer.js", "window.Sys && Sys.UI && Sys.UI._Timer");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxWebForms.js", "window.Sys && Sys.WebForms");
    PreApplicationStartCode.AddMsAjaxMapping("MicrosoftAjaxApplicationServices.js", "window.Sys && Sys.Services");
Here is the Bundle definition for these scripts
bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
                "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
                "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
                "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
                "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));

Here is the ScriptManger registration for these scripts
<asp:ScriptManager runat="server" >
        <Scripts>
            <%--Framework Scripts--%>
            <asp:ScriptReference Name="MsAjaxBundle" />
            <%--Site Scripts--%>
        </Scripts>
    </asp:ScriptManager>
 <asp:ScriptManager runat="server" >
        <Scripts>
            <%--Framework Scripts--%>
            <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
            <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
            <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
            <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
            <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
            <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
            <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
            <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
            <asp:ScriptReference Name="WebFormsBundle" />
            <%--Site Scripts--%>
 
        </Scripts>
    </asp:ScriptManager>

Labels: ,

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: ,
 
test