Posts

Enable CORS in Web Api.

    Generally while we are working with Asp.net Web API , we expose the Web Api by self hosting or host it in different domain or different server .  So CORS (Cross Origin Resource Sharing) comes into play , while we access any Web Api from any other servers or domain which is different from the origin domain . Let me explain it by an example. Suppose my application is running on "http://localhost:61375/". But my Web Api is running on "http://localhost:4000/" . So while we try to access the wep api from the application then we will get an error regarding the CORS . So to make enable the Web Api to accept the request we have to add this few lines of code in WebApiConfig file .  Please add this code inside the Register method. var cors = new EnableCorsAttribute( "http://localhost:61375/" , "*" , "*" ); config.EnableCors(cors);   If you want to allow any request to the Web Api then you can write the following lines

No default service level objective found of edition "GeneralPurpose"

Hi all I got this issue while deploying my .net web application into Azure . In my application I was creating the Database by EnityFramework Code first approach . So after deploying the application to azure ,I changed the connection string . Then when I run my application , I see this error message " No default service level objective found of edition"GeneralPurpose".   This was my connection string. <connectionStrings> <add name= "CodeFirstDataBase" connectionString= "Data Source=tcp:mysite.database.windows.net,1437;Initial Catalog=SchoolCodeFirstDB; User ID=testn;Password=admin;Integrated Security=false;MultipleActiveResultSets=True;App=EntityFramework;" providerName= "System.Data.EntityClient" /> </connectionStrings> So I investigated a lot but could not get a exact solution for it . But this fix worked for me . I just changed  the connection string provide name from  providerName= "System.Dat

Angular 7 application within 5 minutes.

Image
Here I am showing a Angular 7 Hello World application within 2 minutes . In this tutorial I will show you the demo application without brief descriptions . Although I am not describing about the application briefly but it is very interesting . You will just see how easily we can build the Angular 7 application just by few commands.   So before starting this tutorial you should have some basic things. Your machine should have Node.Js and NPM installed . So Lets get started . Step-1 :  Please open command prompt . Step -2 : Then please check the  node.js version by this below command node -v (node.js version should be 8.x or 10.x ) If this given version is not there then please update it below commands npm install npm@latest -g Step-3 : Then please install Angular CLI. Please run the below commands. npm install -g @angular/cli Step- 4 : In this steps just create a work space to create a new angular project . To create the new work space please run the below c

How to create services in Angular 2

Before starting this article you must have some basic knowledge on Angular 2 , typescript and how  to set up the Angular 2 application. If you are a newbie to Angular 2 then you can follow my below links . I am sure you will able to write the Angular 2 applications within 5 minutes. What is typescript ? http://whymysolutions.blogspot.com/2017/09/what-is-typescript.html Angular 2 project set up in Visual studio code and a Small Angular 2 application example. https://whymysolutions.blogspot.com/2018/09/angular2-application-in-visual-studio.html If you are comfortable with basic of Angular 2 then you can directly learn this article step by step. First we will describe the service creation and then we will use it in a small application. Step 1 : Create the service file     First we will create a file having the name as  m ydemoservice.service.ts . Here the *.service.ts* will same but the file name you can change.  Step 2 :  Import the Injectable member into ser

base keyword in C Sharp.

base keyword is used to refer the Base class member . Base class is also called as Parent class and Super class as well. So when to use base Keyword. > To access the base class method which is overridden in child class . > If you want to access the base class constructor while creating the child class object . Lets explain it an example. Case-1 : public class PersonDetails {     protected string name = "John";     public virtual void GetInfo()     {         Console.WriteLine("MyName: {0}", name);     } } class EmployeeDetails : PersonDetails {     public string empid = "AA23";     public override void GetInfo()     {         base.GetInfo();         Console.WriteLine("Employee ID: {0}", empid);     } } class TestClass1 {     static void Main()     {         EmployeeDetails Emp = new EmployeeDetails();         Emp.GetInfo();     } } /* Output : MyName: John Employee ID: AA23 */ Case -2:

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

I was trying to upload a file in client side and sending back the data from the client to Web API controller by angular service . Step 1 : I was doing it by. (It was bot the complete code )   function saveFile(file, cb) {     var readerObj = new FileReader();     readerObj .readAsDataURL(file);     readerObj .onload = function () {         savedFileDataAsBase64Format(readerObj .result, file.name,cb);     };     readerObj .onerror = function (error) {         alert("Error in uploading the file.");     }; Step 2 :     This is my Web api controller action method.        [HttpPost]         [Route("api/FileInput/SaveBase64FileData/{fileName}")]         public void SaveBase64FileData(string fileName, [FromBody]string fileData)         {             byte[] bytes = Convert.FromBase64String(fileData);            // Write code what ever you want to do         } So from the first line of the actions method I was getting the mentioned error. S

What is component in angular.

Image
In this article we will discuss about the component that we are using angular2 application . A angular component mainly consist of three things. 1. Class 2. Template 3. Metadata. We will discuss it one by one . Lets first add a component through Visual studio code. Basically the component is created with .ts extensions and we keep the name as filename.component.ts  . Now we will discuss it one by one. 1. Class : Like other object oriented programming language we declare the class . class is declared with a name and having some property , method and constructor as well. 2. Template :  Template is nothing but an view part of the application . What ever we want to render in the screen that should be mentioned in the template section . Basically the template section contains the HTML content. 3. Metaddata :  Its a extra data used to decorate the angular class for behaving the class properly. Angular2 uses several entries for metadata like annotations, design : pa

Some Javascript interview questions.

1. What should be the output of the following code snippet. const arr = [1, 2, 3, 4]; for (var i = 0; i < arr.length; i++) {   setTimeout(function() {     console.log('Index: ' + i + ', element: ' + arr[i]);   }, 4000); } Output :  Index: 4 ,  element: undefined Explanation : Actually the setTimeout function will create a closure function which have access to the upper local variable i . So once the for loop gets executed the setTimeout function is get executed and the i value goes up . So within this 1 sec the i value goes upto 4 and the arr[4] value would be undefined .