How to send an e-mail via Google SMTP using C#

First things first, some useful StackOverflow links: https://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp https://stackoverflow.com/questions/17462628/the-server-response-was-5-7-0-must-issue-a-starttls-command-first-i16sm1806350 To demonstrate how this is done I first create a new Visual Studio project: Some example code for sending an email via a Google email account (smtp.goolgle.com) – obviously replace this with email / credentials of your own… I put the code within a try-catch block …

Continue reading ‘How to send an e-mail via Google SMTP using C#’ »

How to enable SSL / Https in a Visual Studio Web Api project

useful link is here: https://dotnetcodr.com/2015/09/18/how-to-enable-ssl-for-a-net-project-in-visual-studio/ Create a new Web Api project in Visual Studio: Select/click on the Web API project name in the solution explorer, and then click on the Properties tab. Set ‘SSL Enabled’ to true: The same properties window will also show the HTTPS url for the application. In the above example it’s …

Continue reading ‘How to enable SSL / Https in a Visual Studio Web Api project’ »

Creating a zip archive in C#

StackOverflow link where I got this technique from is here: https://stackoverflow.com/questions/2454956/create-normal-zip-file-programmatically/ First create a new console application: Add references to System.IO.Compression and System.IO.Compression.FileSystem: Select a folder containing a set of files that you would like to archive. You could make this more sophisticated and create your own list of file paths, but I’m just keeping …

Continue reading ‘Creating a zip archive in C#’ »

How to serialize and deserialize Json objects in C#

A simple console app to demonstrate this. After creating your Visual Studio application, console or otherwise, make sure the System.Web.Extension reference is added: Suppose we have an object we wish to serialize/deserialize, such as an instance of this class: One possible way is to make use of the JavaScriptSerializer class. By the way, here is …

Continue reading ‘How to serialize and deserialize Json objects in C#’ »

How to encrypt basic authentication credentials in a Web Api application

This post shows you how to handle encrypted user credentials in a Web Api application and offer further security by enforcing https for all REST api calls. Step 1: Create a new Web Api application: This is our web service that will need to authenticate encrypted user credentials. Step 2: Add a class for handling …

Continue reading ‘How to encrypt basic authentication credentials in a Web Api application’ »

Using basic authentication in a Web API application

Some instructions on how to create implement basic authentication in a Web API application. Just follow what is shown in the steps and screenshots as shown: Step 1: Create a new ASP.NET Web application in Visual Studio: Step 2: Create a new authentication filter I have created a new folder with which to put any …

Continue reading ‘Using basic authentication in a Web API application’ »

Using dependency injection in Web API applications using Unity

Step 1: Create a new ASP.NET Web application Step 2: Install Unity through Nuget At the current time of writing the version used in the Package Manager Console was as follows: Step 3: Create a new repository We add this to the Model folder. When creating the controller in the constructor, We like to specify …

Continue reading ‘Using dependency injection in Web API applications using Unity’ »

How to enforce Https in Web Api server applications

See this post for creating simple Web Api application https://www.technical-recipes.com/2018/getting-started-with-creating-asp-net-web-api-services/ Step 1: Create new Web API project Step 2: Modify the Values controller Comment out [Authorize] requirement and add the [RequireHttps] requirement in ValuesController.cs ValuesController.cs. ValuesController.cs Step 3: Create a new filter Create new Filter Folder: Add new class RequireHttpsAttribute RequireHttpsAttribute.cs Step 4: Update WebApiConfig …

Continue reading ‘How to enforce Https in Web Api server applications’ »

Running ASP.NET Web API services in IIS

To create a very simple ASP.NET Web API service as an example, please see this previous post: https://www.technical-recipes.com/2018/getting-started-with-creating-asp-net-web-api-services/ This will show you how to create a basic Web API service, with example controller, example registration, no authentication etc: Open IIS Manager: Right-click on Sites and select Add web site: You are presented with the Add …

Continue reading ‘Running ASP.NET Web API services in IIS’ »

How to consume a Web API service from a console application

If you do not have an example web service url available here, you can refer to this post to create one for yourself: https://www.technical-recipes.com/2018/getting-started-with-creating-asp-net-web-api-services/ In that example the GET command returns an array of two strings. Create a new console application: For this example we need access to HttpContent.ReadAsAsync. You may have to install this …

Continue reading ‘How to consume a Web API service from a console application’ »