Inject IPrincipal in ASP.NET Web API Controller

In ASP.NET MVC the current IPrincipal can be automatically made available to action methods by implementing the System.Web.Mvc.IModelBinder interface and returning the current authenticated user from HttpContext.User. We can accomplish the same in Web API using the HttpParameterBinding class. namespace App.Web.Http.Helpers { public

Read

OracleDataReader GetOrDefault() extension method

The various GetXXX methods of the OracleDataReader class take a zero-based column index instead of the column name. Referring columns by index instead of name leads to hard to understand code. Additionally, the code may be susceptible to errors if the column order is modified.

Read

Download CSV using ASP.NET Web API

The CsvMediaTypeFormatter on Github makes it possible to support text/csv media type to the Web API stack. However, I wanted to rewrite it using the ToCsv() extension method from my earlier post.

Read

IEnumerable ToCsv() extension method

In a recently concluded project that had many tabular reports, I had to display a link on each report to download the data as a comma-delimited file. Additionally, the downloaded file was expected to have a header row to help identify the columns when imported into excel.

Read

NLog {asp-server-variables} renderer for ASP.NET

The NLog {asp-request} layout renderer requires specifying the keys in the nlog.config file. This works well if we need to log only a few keys. Otherwise, this approach will make the config file difficult to maintain.

Read