Posts

Showing posts from June, 2018

Enable Basic Authentication in WevApi

Image
There are various ways to authenticate a request in WebApi but in this post I am going to talk about how to implement basic authentication in WebApi. The primary purpose of these authentication mechanism is to validate the incoming request. In basic authentication user credentials are hooked-up inside request and you can find it under the authorization header. If you are using third party token base services like oAuth2 to validate the request then these services are also uses the same basic authentication mechanism to validate the user before sharing the token with them. Lets get started Step 1- Create an attribute class and inherits the members of AuthorizeAttribute attribute class. The reason of inheritance is to override the “IsAuthorized” method. public class AuthorizeUser : AuthorizeAttribute     { protected override bool IsAuthorized( HttpActionContext actionContext)         {   }   ...

Add Basic Authentication to ajax request

In this post, I am going to explain how to pass the user credentials to a service that is enabled with basic authentication. In demo example, I have used the ajax jQuery request to connect to a service that validates user based on the credentials that we send in authentication header, if user successfully validated then it will return the data in JSON format and that data will get displayed on webpage in tabular format. If you are interested in getting to know how to enable basic authentication in MVC application, you can refer my this blog. Lets get started Step 1 CDN for   jQuery ,  jQuery min   Step 2 – HTML Code – in this example < table id ="tblProcess">                     < tr >                         < th > Process I...

Add log4net in .Net Application

log4net library If you are planning to use the log4net library for error/info/warning logging in your .net project then this post will help you in that. This post will give you the step by step process to setup and use the log4net library. I have used a slightly different approach to consume the basic methods of log4net.  Instead of creating a static variable of log4net interface, I created a sealed class and inside that created different methods to log the information. I have used the .net framework 4.5 to take the advantages of CompilerServices. If you don’t know about the CompilerServices refer this link . Furthermore, this article is going to explain you how to log the messages in flat file, database logging and sending the log information via email. Lets get started Step 1 – Prerequisite                 Download the latest version of log4net. Or use the neget manager to add the refere...