AngleSharp is a .NET library that gives you the ability to parse angle bracket based hyper-texts like HTML, SVG, and MathML. XML without validation is also supported by the library. An important aspect of AngleSharp is that CSS can also be parsed. The parser is built upon the official W3C specification. This produces a perfectly portable HTML5 DOM representation of the given source code. Also current features such as querySelector or querySelectorAllwork for tree traversal.
Author: Andreas Plahn
.NET C# to SQL Server Data Types Mapping table
SQL Server and the .NET Framework are based on different type systems. For example, the .NET Framework Decimal structure has a maximum scale of 28, whereas the SQL Server decimal and numeric data types have a maximum scale of 38.
Source: SQL Server Data Type Mappings
Permanently Remove the ‘Get Windows 10’ Icon
How to setup wep api to only return json and enable Cors: (web api v2)
In WebApiConfig.cs file from App_Start folder and add the following code in the Register method –
config.EnableCors(); //if cross origin requests should be enabled var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.Remove(config.Formatters.XmlFormatter);
This code does the following:
1. Converts names of properties to camel case while serializing the objects to JSON
2. Removes XML formatter from Web API’s formatters to make sure JSON data is returned on each request
Use this code to easily return json formatted response from api controller:
var employees= EmployeesRepository.GetAllEmployees(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, employees); return response;
Example code for setting up controller and action with cors:
[EnableCors(origins: "http://localhost:55058", headers: "*", methods: "*")]
public classPTEmployeesController : ApiController
{
// GET api/ptemployees
[Route("api/ptemployees")]
public HttpResponseMessage Get()
{
var employees= EmployeesRepository.GetAllEmployees();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, employees);
return response;
}
...
}
From http://www.dotnetcurry.com/aspnet/1063/create-rest-service-using-aspnet-webapi
TypeScript: The Best Way to Write JavaScript
In this continuation of his series, Sahil focuses on TypeScript and why it’s mandatory if you want to write good, reliable code in JavaScript.
IEnumerable VS IQueryable
While query data from database, IQueryable execute select query on server side with all filters (e.g SQL select statement on database server). IEnumerable filters the data on client side. (in memory in application)
IEnumerable Example
- MyDataContext dc = new MyDataContext ();
- IEnumerable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith(“S”));
- list = list.Take<Employee>(10);
Generated SQL statements of above query will be :
- SELECT [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
- WHERE [t0].[EmpName] LIKE @p0
Notice that in this query “top 10” is missing since IEnumerable filters records on client side
IQueryable Example
- MyDataContext dc = new MyDataContext ();
- IQueryable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith(“S”));
- list = list.Take<Employee>(10);
Generated SQL statements of above query will be :
- SELECT TOP 10 [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
- WHERE [t0].[EmpName] LIKE @p0
Notice that in this query “top 10” is exist since IQueryable executes query in SQL server with all filters.
Source: IEnumerable VS IQueryable
Customizing ASP.NET Authentication with Identity: (01) Overview of Identity | Customizing ASP.NET Authentication with Identity | Channel 9
Troy Hunt: Working with 154 million records on Azure Table Storage – the story of “Have I been pwned?”
Setting up and using Azure Table Storage in a simple way:
Be Sure With Azure .NET – Azure Table Storage (Part 1) – CodeProject
For this next article in the series, were going to be looking at Microsoft’ Azure’s Table Storage service.
Source: Be Sure With Azure .NET – Azure Table Storage (Part 1) – CodeProject
Strongly named assemblies in .NET explained
When the assembly is strongly-named, a “hash” is constructed from the contents of the assembly, and the hash is encrypted with the private key. Then this signed hash is placed in the assembly along with the public key from the .snk.
Later on, when someone needs to verify the integrity of the strongly-named assembly, they build a hash of the assembly’s contents, and use the public key from the assembly to decrypt the hash that came with the assembly – if the two hashes match, the assembly verification passes.
It’s important to be able to verify assemblies in this way to ensure that nobody swaps out an assembly for a malicious one that will subvert the whole application. This is why non-strong-named assemblies aren’t trusted in the same way that strongly-named assemblies are, so they can’t be placed in the GAC. Also, there’s a chain of trust – you can’t generate a strongly-named assembly that references non-strongly-named assemblies.