Thoughts on .Net & Coding

.Net Articles, tutorials, reviews, code and more...

  • Self-Hosting an ASP.NET Web API

    ASP.NET Web API can be either be hosted in IIS or in a separate host process. The former approach is usually appropriate when the Web API is part of a web application and one or more web applications are going to consume it. The later approach is suitable when you wish to avoid the overhead of hosting the Web API in IIS and want to have something lightweight. Hosting a Web API inside IIS is quite straightforward as the process is identical to hosting a web application. On the other hand, hosting a Web API in it's own process requires the creation of a host application and is referred as self-hosting. This article shows in step-by-step manner how to self-host a Web API and how to consume it using a client application.

    Read more...

  • What to do when SaveChanges() fails?

    Beginners often ask this question - "What course of action should I take when a call to SaveChanges() fails?" The answer may vary based on a given situation and requirement. This article discusses one way to deal with the errors and shows how to display descriptive error messages to the end user and then rollback the changes made to the model.

    Read more...

  • Passing data from one controller to another in ASP.NET MVC

    At times you need to pass data from an action method belonging to one controller to an action method belonging to another controller. There are three ways to accomplish this task. They are - Pass data as query string, pass data in TempData, and pass data as route parameters. Let's quickly see how each of these three approaches work.

    Read more...

  • Overview of OWIN and Katana

    As OWIN is becoming popular and more common, it is important for ASP.NET developers to understand what OWIN and Katana are. ASP.NET Web API and ASP.NET Identity are already geared towards using these specifications. To that end this article explains what OWIN and Katana are and how they fit into the whole web development picture for ASP.NET developers. You will also develop a simple application to get a code level understanding of these features.

    Read more...

  • Creating Your Own "TempBag" in ASP.NET MVC

    Some time back during one of my training programs I was asked this question by a beginner in ASP.NET MVC - "Can we have TempBag wrapper for TempData just as we have ViewBag for ViewData?" Whether such a wrapper is needed is not is a different question but if you wish you can create one using dynamic objects of C# language. Here I am going to show a quick way to wrap TempData into our own TempBag and then using it in the controller and view.

    Read more...

  • Video : How to Organize Your ASP.NET MVC Solution in Visual Studio?

    A lot of beginners ask this question - How should I organize my MVC projects? There is no fixed answer to this question because a lot of things depend on the size and complexity of the system being developed. However, beginners need a starting point from where they can take it forward. To that end, this video shows one possible organization of various parts of an MVC application. Remember that my aim is to present a simple and structured organization that can easily be extended or modified as per requirement.

    Read more...

  • Working with Cookies in Web API and HttpClient

    ASP.NET applications often use cookies to store user specific pieces of information. Not just web forms and MVC applications, Web API too can use cookies. Sometimes developers device an authentication scheme revolving around cookie as an authentication ticket. Although this article won't show you how to develop such a scheme, it illustrates how cookies can be issued and used in Web API. Specifically you will learn: How to set cookies from a Web API controller and read those cookies in a client application and how to set cookies from a client application (HttpClient) and read those cookies in a Web API controller.

    Read more...

  • Learn ASP.NET MVC5, EF6, Web API 2, VS 2013 in Thane

    I will be conducting a 5 day intensive training program on ASP.NET MVC in the month of July 2014. Learn VS2013, MVC5, EF6, Web API 2 and more. Small batches, personal attention and real world examples. Registration has already started. In case you or your friends are interested to join please get in touch with us as soon as possible.

    Read more...

  • Understanding Dependency Injection

    If you ever developed ASP.NET MVC applications you probably have come across this term - Dependency Injection. Dependency Injection is a way to implement the Dependency Inversion Principle. Simply put, Dependency Injection is a design pattern that helps a class separate the logic of creating dependent objects. The result of this separation is a loosely coupled system where there is no rigid dependency between two concrete implementations. This article discusses what Dependency Injection is and illustrates its use in an ASP.NET MVC application.

    Read more...

  • Dealing with Multiple Instances of Partial Views and Model Binding in ASP.NET MVC

    ASP.NET model binding is quite powerful and flexible. It caters to most of the scenarios without much configuration from developers. However, at times you may need to intervene in order to achieve the desired model binding effect. One such situation is when you use multiple instance of a partial page on a view. This article shows one possible approach to deal with such situations.

    Read more...