Handle multiple button post

razor: <form action=”” method=”post”> <input type=”submit” value=”Save” name=”action:Save” /> <input type=”submit” value=”Send” name=”action:Send” /> </form> and controller: [HttpPost] [MultipleButton(Name = “action”, Argument = “Send”)] public ActionResult Send(MessageModel mm) { … } [HttpPost] [MultipleButton(Name = “action”, Argument = “Save”)] public ActionResult Save(MessageModel mm) { … }

Continue reading

Handle the unhandled exception in Window Service C#

Sometimes window service crash due to unhandled exception occur in the code. Which cause service to be on halt without any error log and we are unable to restart or stop the service in the windows. In .net framework 4.5, Microsoft provides a method to handle the exception in the async event handler. Simply write…

Continue reading

ASP.NET Web API 2 action method return types

A Web API 2 action method return types can be any of the following : Void HttpResponseMessage IHttpActionResult Other type or Complex type   Void When an ASP.NET Web API return type is void, it will return an empty HTTP response. In the following example a web API with void return: Example public class SampleController…

Continue reading

Content negotiation in WebAPI or other rest service.

The Accept header is used by HTTP clients to tell the server what content types they’ll accept. The server will then send back a response, which will include a Content-Type header telling the client what the content type of the returned content actually is. However, as you may have noticed, HTTP requests can also contain Content-Type headers. Why? Well, think about POST or PUT requests….

Continue reading

Difference between Covariance & Contravariance

It’s probably easiest to give examples – that’s certainly how I remember them.  (covariant return types/contravariant parameter types) Covariance Canonical examples: IEnumerable<out T>, Func<out T> You can convert from IEnumerable<string> to IEnumerable<object>, or Func<string> to Func<object>. Values only come out from these objects. It works because if you’re only taking values out of the API, and it’s going to return something specific (like string), you can…

Continue reading

Difference between Encapsulation and Abstraction in OOPS

Abstraction and Encapsulation are two important Object Oriented Programming (OOPS) concepts. Encapsulation and Abstraction both are interrelated terms. Real Life Difference Between Encapsulation and Abstraction Encapsulate means to hide. Encapsulation is also called data hiding.You can think Encapsulation like a capsule (medicine tablet) which hides medicine inside it. Encapsulation is wrapping, just hiding properties and methods. Encapsulation…

Continue reading

Content negotiation in Web API(accept and content-type attribute of header)

Content negotiation is a way to serve client-specific representations of the same resource. A client might send this HTTP request: GET http://localhost.:21069/api/products/1 HTTP/1.1 Host: localhost.:21069 Accept: application/json, text/javascript, */*; q=0.01 In response, the server might send: HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Content-Length: 57 Connection: Close The Accept header is used by HTTP clients to…

Continue reading

Single vs SingleOrDefault vs First vs FirstOrDefault

When to use Single, SingleOrDefault, First and FirstOrDefault You should take care of following points while choosing Single, SingleOrDefault, First and FirstOrDefault: When you want an exception to be thrown if the result set contains many records, use Single or SingleOrDefault. When you want a default value is returned if the result set contains no…

Continue reading