Convert a List of items to an XElement in C#

I have always used XElement.Parse() and StringBuilder to create an XElement of a required type. Today I came across this post on some blog and then this thread on stackoverflow which show how to do the same in a more efficient manner. Sharing it here hope this helps. Requirement 1: <students> <student>1</student> <student>2</student> <student>3</student> <student>4</student> […]

Serialize a List of Object to JSON in C#

This can be easily be done using Json.NET. Json.NET is a popular high-performance JSON framework for .NET. First of all, you will need to download the latest binary from here and include it your project. using Newtonsoft.Json; Rest of the code is pretty self explanatory… public class Employee { public string FirstName { get; set; […]

Using Facebook Login with ASP.NET MVC 4

Login with Facebook is a very common feature that you will come across on the registration/login page on almost all good websites. ASP.NET MVC 4 includes support for OAuth and OpenID providers. Using these providers, you can let users log into your site using their existing credentials from Facebook, Twitter, Microsoft, and Google. MVC 4 […]

A Beginners Guide to IIS Logging

IIS Internet Information Server is one of the most powerful web servers provided by Microsoft that is able to host and run your web applications. IIS supports the following protocols: FTP, FTPS, SMTP, NNTP, HTTP/HTTPS. We can host our web sites on IIS, we can use it as an FTP site also. For more information, […]

How to Focus element using pure HTML ? How to set CSS for on Focus?

To set focus on page load using pure html you can use the autofocus keyword. Here is an example on JsFiddle. And to set the css for on focus use the :focus selector in your css. Below is the sample code I have used. <form> <input type=”text” id=”FirstName” placeholder=”First Name” autofocus> <input type=”text” id=”LastName” placeholder=”Last […]

How to add additional fields when using Membership in ASP.NET MVC 4

1. Modify your UserProfile class Here in this example I am adding a new field called “MobileNumber“, have declared it as type string. [Table("UserProfiles")] public class UserProfiles { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int UserId { get; set;} public string Email { get; set;} public string FirstName { get; set; } public string LastName { get; set; […]

Flat UI theme for ASP.NET MVC Web App

Nowadays Flat UI has become very popular with any developers and desginers, all major websites, web app and even mobile apps have shifted to Flat UI. I recently saw this Flat UI – Free User Interface Kit and I created this template for ASP.NET MVC built website. The code has been downloaded for view from […]

Custom Authorization in ASP.NET MVC 3 using IAuthorizationFilter & FilterAttribute

Authorization filters : These implement IAuthorizationFilter and make security decisions about whether to execute an action method, such as performing authentication or validating properties of the request. This post demonstrates how to create a custom authorization filter. Step 1 : Create the Authorization Attribute and Filter: ///marker attribute public class CustomAuthorizeAttribute : FilterAttribute { } […]

How to use distinct() method on property of a class in C#

Distinct() is used to remove all duplicate items from a list or a collection. To use this method on a property of a class, below is an extension method which you could use : public static class MoreLinq { public static IEnumerable<T> DistinctByProperty<T, TKey>(this IEnumerable<T> items, Func<T, TKey> property) { return items.GroupBy(property).Select(x => x.First()); } […]

How to create a Google Chrome App?

Step 1: Create the manifest Every extension, installable web app, and theme has a JSON-formatted manifest file, named manifest.json, that provides important information. First create your manifest.json file using the format shown here. { “name”: “Code Formatter”, “description”: “A chrome plugin to format your HTML, CSS, JS, SQL or JSON code.”, “version”: “0.1″, “app”: { […]