It’s easy by using the HttpContextWrapper HttpContextBase basecontext = (new HttpContextWrapper(HttpContext.Current)); Happy coding!
Month: February 2016
How to check if IsNumeric?
If you need to check if something is a number, in C# doesn’t exist a function for that. That I’ve created the following code. public bool IsNumeric(object Expression) { if (Expression == null || Expression is DateTime) return false; if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean) return true; try { if (Expression is string) Double.Parse(Expression as string); else Double.Parse(Expression.ToString()); return true; } catch { } // just dismiss errors…
Remove line numbers from code
Often you copy from a site some code but it has line numbers and you have to spend some times to remove them. With my simple tool on line, you can remove them quickly. Try it!
Customize Json result in Web API
If you work with Visual Studio 2015 and WebAPI, this short post is for you! We have to make our Web API project easy to debug so, I’m going to remove the XML formatter. I’m doing that because I’m in a test project and I’d like to see the response in the browser. The easily way to force the response to Json for all Web API requests is to remove the XML. Obviously you shouldn’t do it in production. Global.asax var formatters = GlobalConfiguration.Configuration.Formatters; formatters.Remove(formatters.XmlFormatter); Now we can start change…
Creating a URL shortener using ASP.NET WepAPI and MVC: error handling
In the two previous post I discussed about the first step to creare this application and the implementation of the business logic. Now we can implement the error handling. We have two custom exception classes: ShorturlConflictException (when a segment already exists) and ShorturlNotFoundException (when a segment isn’t found in the database). There is also a third type: an unexpected exception, for example when there is no database connection. Normally, the user will see these errors. We have to build a mechanism where these exceptions are caught and a nice error…
Creating a URL shortener using ASP.NET WepAPI and MVC: implementing the business layer
In my previsious post I discussed the first implementation of this application. In this post I’m explained how to implement the business layer. First of all you make sure the Business project references the Data, Entities and Exceptions projects. In the Exceptions project you add two new classes: ShorturlConflictException using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PSC.Shorturl.Web.Exceptions { public class ShorturlConflictException : Exception { } } ShorturlNotFoundException using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PSC.Shorturl.Web.Exceptions { public class ShorturlNotFoundException : Exception {…
Agile approaches
There are a number of specific Agile approaches, as well as a generic agile style of working. Extreme Programming is a software development methodology, containing mainly programming practices such as Test Driven Development, Pair programming and Continuous Integration, but little management. Lean, which came from the manufacturing environment, is all about efficient processes. The focus is on eliminating waste from the production line and thereby reducing cost. Scrum is a very simple agile process, designed for delivering software in small chunks, taken from a backlog of work to be done.…