Skip to main content

Posts

Showing posts from January, 2018

Rotate a image.

Here I will explain how to rotate a image. public void FlipImage(string Filename, string NewFileName) { System.Drawing.Image img = System.Drawing.Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath("/images/") + Filename); //Rotate the image in memory img.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); System.IO.File.Delete(System.Web.Hosting.HostingEnvironment.MapPath("/images/" + NewFileName)); //save the image out to the file img.Save(System.Web.Hosting.HostingEnvironment.MapPath("/images/" + NewFileName)); //release image file img.Dispose(); }

Node JS service using MSSQL server.

Here I will explain how to connect sql database in node js service. you can call this service from angular js, jquery etc. we require express and mssql packages for this.  First of all we attach require packages. you have download this packages using npm in your project. var express = require('express'), app = express(); var sql = require('mssql'); Then after configure your database credentials. var config = { user: 'USERNAME', password: 'PASSSWORD', server: 'SERVER IP', database: 'DBNAME', pool: { max: 100, min: 0, idleTimeoutMillis: 3000000 }, options: { encrypt: true } }; Here I have created object of sql connection and call connect method of this. var connection = new sql.Connection(config); connection.connect(); here i have created get method. app.get('/Your service name', function (req, res) { //attach header for cross platf

Selection Sort Algorithm Using JavaScript

Here I will explain how to sort array element. function SelectionSortAlgorithm(input) { for (var i = 0; i < input.length; i++) { var str = input[i]; for (var j = i + 1; j < input.length; j++) { if (str > input[j]) { str = input[j]; } } var index = input.indexOf(str); var strVal = input[i]; input[i] = str; input[index] = strVal; } } var input = [11,44,7,3,2,5,8,4,0,1,16,9]; console.log(input); SelectionSortAlgorithm(input); console.log(input); Output: [44, 16, 11, 9, 8, 7, 5, 4, 3, 2, 1, 0] [0, 1, 2, 3, 4, 5, 7, 8, 9, 11, 16, 44]

How to apply Basic Authentication In Web API.

Here, I will explain how to maintain security in webapi Step : 1 Create a method for validate loginname and tokenkey. if exists then return true otherwise return false. public static bool Vaidatecredentials(string loginname, string tokenkey) { // Check if it is valid credential if(true)//Check login name and token key exists in DB(loginname, password)) { return true; } else { return false; } } Step : 2 add a class, which is used as Authorization filter. The class BasicAuthenticationAttribute inherits from BasicAuthenticationAttribute abstarct class. public class BasicAuthenticationAttribute : AuthorizationFilterAttribute { public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { if (actionContext.Request.Headers.Authorization == null) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unau

Set header globally in ajax call.

Here i will explain how to set global header in ajax call. I have used beforesend event to set header before calling ajax mathod. $.ajaxSetup({     beforeSend: function (xhr) {         xhr.setRequestHeader("Accept", "application/vvv.website+json;version=1");                xhr.setRequestHeader("Authorization", "Basic abc");     } });