Posts

Azure API: Why does my API in the API Management Developer Portal not have a subscription key?

Image
I encountered this problem recently when trying to add an API to my API Management. I followed all the steps but my API execution complained that the subscription key was missing. The reason for the error is that my API was not associated to a Product. To fix this, 1. Open the Publisher Portal from 'Overview' option in the API Management blade 2. Navigate to the 'Products' tab and assign the API to a product 3. Now navigate to the Developer Portal and subscription key value is now set in the request header.

How can I document my API with Swagger?

Image
Swagger has provided a very simple way to document your APIs. I created a simple OOTB Web Application with the Web API template. To create the swagger output: 1. Add the SwashBuckle nuget package 2. Publish the API and navigate to <API URL> /swagger/docs/v1 . This will create the swagger json 3. Save the file in a swagger.json file in the solution. 4. Open the file with the  http://editor.swagger.io/#/ to retrieve the documentation.

C#: How do I create a comma separated list from an object?

        public static string CreateCSVFromObject(object obj)         {             if (obj == null)             {                 throw new ArgumentNullException("obj", "Value can not be null or Nothing!");             }             StringBuilder sb = new StringBuilder();             Type t = obj.GetType();             PropertyInfo[] pi = t.GetProperties();             for (int index = 0; index < pi.Length; index++)             {                 sb.Append(pi[index].GetValue(obj, null));                 if (index < pi.Length - 1)        ...

How can I create a generic data repository for my Entity Framework solution?

I recently created a quick console application that required CRUD activities on a SQL database. I had a few tables to update and did not want the headache of creating multiple items in my DAL. Enter a generic data repository. The code is pretty simple: 1. Create a base interface for the CRUD operations public interface IGenericDataRepository<T> where T : class     {         List<T> GetAll(params Expression<Func<T, object>>[] navigationProperties);         List<T> GetList(Func<T, bool> where, params Expression<Func<T, object>>[] navigationProperties);         T GetSingle(Func<T, bool> where, params Expression<Func<T, object>>[] navigationProperties);         void Add(params T[] items);         void Update(params T[] items);         void Remove(params T[] items);     ...

Azure: How do I create an MVC site to load files to BLOB storage?

I recently created a simple POC site to load files to blob storage containers in Azure. Here is how I achieved it. My code is based on the sample provided  here After creating a simple MVC web project, I added the following nuget packages: DropZone WindowsAzure.Storage Microsoft.WindowsAzure.ConfigurationManager The code is pretty simple: Here is Index.cshtml: @model List<string> <script src="~/Scripts/dropzone/dropzone.min.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <link href="~/Scripts/dropzone/dropzone.min.css" rel="stylesheet" /> <div class="jumbotron">     <h2>FILE UPLOAD</h2>     <form action="~/Home/Upload"           class="dropzone"           id="dropzoneJsForm"           style="background-color:#00BFFF"></form>         <button id="refresh" onc...

CSS: How do I create a spinning 'loading' icon using an image

Image
The icon can be created using the following simple classes .loading{background:url(../img/loading-purple.gif) no-repeat center} .loading > div{display:none} Here is a sample image that could be used. Too easy. However, this is old school. You can create a simpler one using CSS and HTML5. Here is the CSS: .loading-container{display:block;width:100%;min-height:45%;margin-top:60px;text-align:center} .loader {margin:0 auto;text-align:center;width:200px;min-height:100%;display:block;vertical-align:middle} .loader:hover{opacity:1} .loading-spinning-bubbles{position:relative;margin:auto;min-height:1px} .loading-spinning-bubbles .bubble-container {position:absolute;top:calc(50% - 10px/2);left:calc(50% - 10px/2);transform-origin:-150% 50%;-webkit-transform-origin:-150% 50%;-moz-transform-origin:-150% 50%} .loading-spinning-bubbles .bubble-container .bubble {background:#00ac00;width:10px;height:10px;border-radius:50%;animation:bubble 1s infinite;-webkit-animation:bubble ...

Web API: How do I clean up the data in my HttpResponse?

There are some very simple web.config settings that can be applied to reduce the amount on unnecessary data returned in an HttpReponse and to minimise ways that hackers can hijack system information. Here is a quick snippet of web.config settings that may be useful. <Config> <system.web>  <httpRuntime enableVersionHeader="false" /> </system.web> <system.webServer> <httpProtocol>  <customHeaders> <add name="Strict-Transport-Security" value="778000; includeSubdomains" /> <add name="X-Content-Type-Options" value="nosniff" /> <add name="X-Permitted-Cross-Domain-Policies" value="none" /> <add name="X-XSS-Protection" value="1; mode=block" /> <add name="Cache-Control" value="no-store" /> <add name="Pragma" value="no-cache" /> <remove name...