Thursday, October 29, 2015

What is JSON?

JSON

- JSON stands for Javascript Object Notation.
- It's a message format, used for interchanging data.
- JSON is based on the Javascript.
- JSON is lightweight than XML and modern webservices use JSON to exchange data.
- JSON can store data in Name/Value pairs and Ordered List.

Here is a simple example of JSON. 

{"employees":[
    {"firstName":"John""lastName":"Doe"},
    {"firstName":"Anna""lastName":"Smith"},
    {"firstName":"Peter""lastName":"Jones"}
]}


Monday, October 26, 2015

Advantages of using Stored Procedures.

1. They help in reducing the network traffic and latency which in turn boosts application performance. 
2. They help in promoting code reuse. 
3. They provide better security to data. 
4.  It is possible to encapsulate the logic using stored procedures. This allows to change stored procedure code without affecting clients. 
5.  It is possible to reuse stored procedure execution plans, which are cached in SQL Server's memory. This reduces server overhead.

Thursday, October 22, 2015

How to prevent partial page to access directly in asp.net MVC.

Use the ChildActionOnly Attribute on Action of your Controller. 
For example:

        [HttpGet]
        [ChildActionOnly]
        public ActionResult GetProductList() {
            var vm = new ViewModels.EntryListViewModel(Models.UIdentity.Id);
            return View(vm);
        }

ASP.NET MVC DisplayFor Html Helper Set Default Value

Use use DisplayFor Html Helper for displaying our model text in to razor view. It is actually render Span <span> tag in our html document. Sometime our Model returns null values and we required to display the text over null value like this. "Null" , "N/A" ,"$0.00" and so on...
Here is the simplest solution.

In your Model Class (C#). 


Import the namespace:
using System.ComponentModel.DataAnnotations;

Decorate the your property. 

[DisplayFormat(NullDisplayText="N/A")]
public string LabelText { get; set; }

Thats it!. 

Tuesday, October 20, 2015

Remove dash from GUID in C#

C# 
Guid.NewGuid().ToString("N");

Difference between encoding and Encryption


Encoding: transforms data into another format using a scheme that is publicly available so that it can easily be reversed and can be transmitted without danger over a communication channel or stored without danger on a storage medium. 
Algorithms Used in Encoding: ASCII, Unicode, URL Encoding, Base64. 
Example: Binary data being sent over email, or viewing special characters on a web page.

Encryption: transforms data into another format in such a way that only specific individual(s) can reverse the transformation.
Encryption method uses secret keys : the algorithm is well-known, but the encryption and decryption process requires having the same key for both operations, and the key is then kept secret.
Algorithms Used in Encryption: AES, Blowfish, RSA ...  
Example: Sending someone a secret letter that only they should be able to read, or securely sending a password over the Internet.

Monday, October 19, 2015

C#: Converting Object in to JSON

This is not the single way to serializing object into JSON, but the simple way is to do that. 

1. Download the Newtonsoft JSON serializer. 
2. Reference the DLL. 
3. Using the namespace in your class. 


C# Code. 


namespace:

using Newtonsoft.Json;


 public string GetData(string name)
        {
            person p = new person();
            p.name = name;
            return JsonConvert.SerializeObject(p);
        }
    }