How to get Query Params in Web API ASP.Net C# from Request

Since ApiController was made to work without IIS Hosting, it does not depend upon the HttpContext object. We need System.Net.Http namespace to get the extension method GetQueryNameValuePairs() Request.GetQueryNameValuePairs() To get the param values from the query string, we need another namespace System.Linq URL: http://localhost/Person?query=test Request.GetQueryNameValuePairs().Where(nv => nv.Key == “query”).Select(nv => nv.Value).FirstOrDefault()

Continue reading


Get Slug of string using c#

public static string ToSlug(string value) { //First to lower case value = value.ToLowerInvariant(); //Remove all accents var bytes = Encoding.GetEncoding(“Cyrillic”).GetBytes(value); value = Encoding.ASCII.GetString(bytes); //Replace spaces value = Regex.Replace(value, @”\s”, “-“, RegexOptions.Compiled); //Remove invalid chars value = Regex.Replace(value, @”[^\w\s\p{Pd}]”, “”, RegexOptions.Compiled); //Trim dashes from end value = value.Trim(‘-‘, ‘_’); //Replace double occurences of – or \_ […]

Continue reading


Difference between Configuration.cs vs Database Initializer in Entity Framework

Difference between Configuration.cs vs Database Initializer in Entity Framework Configuration.cs file located inside Migrations folder, which will be created when we execute the command “Enable-Migrations” in Package Manager Console. We can make use of this class for seeding the datas into database. This class will seed the database whenever we execute the Update-Database command in […]

Continue reading