Featured

    Featured Posts

Handle no 'Access-Control-Allow-Origin' - issues on client side in ASP.NET WebAPI

Since your .NET Web API and Client-Side projects are being hosted on different ports, it's considered a Cross-Domain (CORS) request.

Just add the proper header in your web.config from your web API application:

<configuration>
  <system.webServer>
    <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />    
       <add name="Access-Control-Allow-Headers" value="Content-Type" />
       <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
     </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

Generate invoice number through c#

In this article i will show you how to generate invoice number through c# in form of AJ0001/001, AJ0001/002 ...

    int invoiceNo = 1;
    while (Console.ReadLine() != "stop")
    {
        for (int i = 1; i <= 100; i++)
        {
            Console.WriteLine("{0}/{1}", invoiceNo.ToString("AJ0000"), i.ToString("000"));
        }
        invoiceNo++;
    }

Get address from Google Map API JSON response through Latitude and Longitude in C#

In this article I will explain how to get address of a location from help of geographical position coordinate Latitude and Longitude using Google Map API JSON response in C#.

We need to implement two namespace in our C# code

using System.Net;
using System.Web.Script.Serialization;

When we pass parameter i.e. Latitude and Longitude to our function that will return address of that location.

public string getAddress(string lat, string lng)
{
    string returnVal = string.Empty;
    string url = string.Format("http://maps.googleapis.com/maps/api/geocode/json?latlng={0},{1}", lat, lng);
    using (WebClient client = new WebClient())
    {
        string json = client.DownloadString(url);
        GoogleResponseData addressInfo = (new JavaScriptSerializer()).Deserialize<GoogleResponseData>(json);
        returnVal = addressInfo.results[0].formatted_address;
    }
    return returnVal;
} 
When we hit Google Map API then it return JSON data so we have to serialize and deserialize JSON object. For this we need some class to map those data.

 public class GoogleResponseData
{
    public string status { get; set; }
    public results[] results { get; set; }

}
public class results
{
    public string formatted_address { get; set; }
    public geometry geometry { get; set; }
    public string[] types { get; set; }
    public address_component[] address_components { get; set; }
}
public class geometry
{
    public string location_type { get; set; }
    public location location { get; set; }
}
public class location
{
    public string lat { get; set; }
    public string lng { get; set; }
}
public class address_component
{
    public string long_name { get; set; }
    public string short_name { get; set; }
}





 
When we hit Google Map API then it return JSON data so we have to serialize and deserialize JSON object. For this we need some class to map those data.

Display only Date in ASP.NET MVC view

Display only date into Razor View in ASP.NET MVC

Write this code in your View
@Convert.ToString(string.Format("{0:dd/MM/yyyy}", item.birthDay))

www.CodeNirvana.in

Copyright © Kodexpression