Saturday, June 21, 2014

Interview Questions - 2014

Difference between the following

  • Except, Intersect, Union
  • Truncate, Delete
  • Abstract, Interface
  • Single, First - Linq
  • var, dynamic, object
  • IEnumerable, IQueryable
  • IList, List

http://msdn.microsoft.com/en-us/library/scsyfw1d(v=vs.71).aspx

http://www.dotnet-tricks.com/Tutorial/csharp/5LQ6210314-Differences-between-Object,-Var-and-Dynamic-type.html

http://www.dotnet-tricks.com/Tutorial/linq/I8SY160612-IEnumerable-VS-IQueryable.html

BlockingCollection

ActionResult - http://msdn.microsoft.com/en-us/library/system.web.mvc.actionresult(v=vs.118).aspx

ActionFilters - http://msdn.microsoft.com/en-us/library/dd410209.aspx
AuthorizeAttribute, OutputCacheAttribute, HandleErrorAttribute 
Cross-site scripting - http://msdn.microsoft.com/en-us/library/ff649310.aspx
HTTP Handlers & Modules - http://msdn.microsoft.com/en-us/library/vstudio/bb398986(v=vs.100).aspx
http://www.codeproject.com/Articles/30907/The-Two-Interceptors-HttpModule-and-HttpHandlers
https://www.simple-talk.com/sql/sql-training/the-sql-server-query-optimizer/
http://msdn.microsoft.com/en-us/library/ff650689.aspx




Saturday, April 20, 2013

Whats new in ASP.NET MVC 3 and 4


What's New in ASP.NET MVC 3
  • Razor view engine
  • Improved model validation with unobtrusive JavaScript and jQuery support. 
  • remote validation
  • Partial page output caching.
  • Dependency Injection Improvements, new IDependencyResolver, (we use Castle Windsor)
  • Integrated Scaffolding system extensible via NuGet
  • HTML 5 enabled project templates
  • Controller Improvements: Global Action Filters, ViewBag, ActionResult


What's New in ASP.NET MVC 4
  • ASP.NET Web API
  • Refreshed and modernized default project templates
  • New mobile project template
  • Many new features to support mobile apps
  • Enhanced support for asynchronous methods

Sunday, April 14, 2013

Whats new in .NET Framework 4.5

.NET Framework 4.5

1) ASP.NET & VS.NET 2012
  • bundling and minification - Javascript & css file size reduced and loaded fast
  • asynchronous web programming (http://www.asp.net/web-forms/tutorials/aspnet-45/using-asynchronous-methods-in-aspnet-45)
  • In ASP.NET, now model binders can be used for data access like in ASP.NET MVC. If model binders used, data-bound controls can call code directly, like action methods in ASP.NET MVC.
  • pages perform better through unobtrusive JavaScript
  • HTML5 & CSS3 support
  • Now browser can be selected to test the web application
  • Javascript editor
  • IIS Express
  • ASP.NET Web API
2) .NET Framework 4.5
3) WCF
  • Task-based Async Support
  • Simplified Generated Configuration Files
  • WCF Configuration Validation
  • XML Editor Tooltips
  • WCF binary encoder adds support for compression
Asynchronous programming / Task-based Asynchronous Pattern

ASP.NET 4.5 Web Pages in combination .NET 4.5  enables you to register asynchronous methods that return an object of type  Task. The .NET Framework 4 introduced an asynchronous programming concept referred to as aTask and ASP.NET 4.5 supports Task. Tasks are represented by the Task  type and related types in theSystem.Threading.Tasks namespace. The .NET Framework 4.5 builds on this asynchronous support with  the awaitand async keywords that make working with Task objects much less complex than previous asynchronous approaches.  The await keyword is syntactical shorthand for indicating that a piece of code should asynchronously wait on some other piece of code. The async keyword represents a hint that you can use to mark methods as task-based asynchronous methods.  The combination of awaitasync, and the Task object makes it much easier for you to write asynchronous code in .NET 4.5. The new model for asynchronous methods is called the Task-based Asynchronous Pattern (TAP).

Friday, March 25, 2011

Removing validation errros of unused fields ASP.NET MVC

We are using ORM tools to create our Model objects and we may not be using all the properties in the page, So validation is going to be thrown irrespective of the properties used in the page.

In these scenarios we can use ActionFilterAttribute. We should override the OnActionExecuting method to remove the validations for un used properties.

public class UsedFieldsOnlyValidationAttribute : ActionFilterAttribute{

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var modelState = filterContext.Controller.ViewData.ModelState;
var valueProvider = filterContext.Controller.ValueProvider;

var keysWithNoIncomingValue = modelState.Keys.Where(x => !valueProvider.ContainsPrefix(x));
foreach (var key in keysWithNoIncomingValue)
{
modelState[key].Errors.Clear();
}
}
}

Submit Link Button for ASP.NET MVC

We are using submit buttons (input type=submit) for submitting the form back to the server.

We have other buttons in the page as link button, so we had different look & feel between submit button and others.

We wanted create a submit button that looks like other link button as well as it should do the submit functionality by own.

So we decided to create a extension method.

To submit the page, i used the below code in the href.
document.forms['" + formId + "'].action = '" + href + "';
document.forms['" + formId + "'].method = 'POST';document.forms['" + formId + "'].submit();


To manually call the microsoft client side validation, i used the below code in the href.
Sys.Mvc.FormContext.getValidationForForm(document.forms['" + formId + "']).validate('submit').length

Find the extension method below

public static MvcHtmlString SubmitLinkButton(this HtmlHelper helper,
string caption,
string actionName,
string id,
string formId,
RouteValueDictionary routeValues = null,
Dictionary htmlAttributes = null)
{
return CreateLinkButton(helper, caption, actionName, id, routeValues, htmlAttributes, formId, null);
}

private static MvcHtmlString CreateLinkButton(HtmlHelper helper,
string caption,
string actionName,
string id,
RouteValueDictionary routeValues = null,
Dictionary htmlAttributes = null,
string formId = null,
string href = null)
{
string cssClass = "t-grid-action t-button t-state-default";

if (href != null)
{
href = "#";
}
else
{
formId = formId ?? "0";
//creating href string
href += "/" + helper.ViewContext.RouteData.Values["controller"].ToString();
href += "/" + actionName;
//QueryString can be found here - helper.ViewContext.Controller.ControllerContext.HttpContext.Request.QueryString
if (routeValues != null && routeValues.Count > 0)
{
href += "?";
href = routeValues.Aggregate(href, (current, routeValue) => current + (routeValue.Key + "=" + routeValue.Value + "&"));
href = href.Substring(0, href.Length - 1);
}
href = "javascript:{if (!Sys.Mvc.FormContext.getValidationForForm(document.forms['" + formId + "']).validate('submit').length) { document.forms['" + formId + "'].action = '" + href + "';document.forms['" + formId + "'].method = 'POST';document.forms['" + formId + "'].submit();}}";
}

var linkButtonBuilder = new TagBuilder("a");
linkButtonBuilder.GenerateId(id);
linkButtonBuilder.MergeAttributes(htmlAttributes);
linkButtonBuilder.AddCssClass(cssClass);
linkButtonBuilder.MergeAttribute("print_mode", "hide");
linkButtonBuilder.MergeAttribute("href", href);
linkButtonBuilder.SetInnerText(caption);

return MvcHtmlString.Create(linkButtonBuilder.ToString());
}

Monday, January 31, 2011

Restarting Windows7 machines

We can use the following shutdown command to restart or logoff windows 7 machines from local or remote.

Shutdown /? - help
Shutdown /i - ui, where we can set action, reason, machine name(s)
Shutdown -r - restart

This is excellent one when working in the machine remotely and need a restart. This is very helpful for the admins too.

Monday, January 3, 2011

TryUpdateModel vs Model.IsValid

I am intensively working in asp.net mvc since last September and below is my findings about TryUpdateModel and Model.IsValid.

TryUpdateModel
This method can be used to bind the view to model when we didn't pass the model as parameter to action method. This has multiple overloads that will help to set only specific object if multiple subobjects found in the model, exclude some properties and so on. For your info, this method's last line returns the Model.IsValid.

Public ActionResult Update(string id)
{
//getting the object from the db
object obj = GetObjectById(id);
//binding the view to the model and validating the model
If(TryUpdateModel(obj))
{
UpdateObject(obj);
RedirectToAction("Index");
}
return View(obj);
}

Model.IsValid

This can be used to validate the model when we pass the model as a parameter. When we pass the model as a parameter the model binding is happening automatically and validation status is set to IsValid.

Public ActionResult Update(object obj)
{
//binding the view to the model and validating the model
If(Model.IsValid)
{
UpdateObject(obj);
RedirectToAction("Index");
}
return View(obj);
}