Posts

Showing posts from March, 2014

Load MVC view to jquery color box

  You can use the following set of code to load a MVC view to a jquery color box. You can get more details on jquery colobox here . HTML code < table cellpadding ="0" cellspacing ="0" border ="0" class ="display" id ="ClientConfigurationList" style =" width : 100%" >          < thead >              < tr >                                                < th > Work Order No </ th >                  < th > Work Order Status </ th >                  < th > Created On </ th >                  < th > Completed On </ th >                  < th > Asset Description </ th >              </ tr >          </ thead >          < tbody >              @ foreach ( var item in Model)              {                  < tr class ="leftAlign">                                                         ...

Dynamically Load External JS , CSS file paths in webconfig

  If you want to load JavaScript paths or CSS paths saved in web config app settings you can use the following solution. Step 1: Create a API controller method which will return the appsettings public class ConfigurationController : ApiController   {          [ HttpGet ]        public string LoadSettings(Domain.Entities. Configuration model)   {       string value = ConfigurationManager .AppSettings.Get(model.Key);       return value;   }   }   Step 2: Create a javascript function which will load javascript or css paths dynamically. function loadjscssfile(filename, filetype) {        if (filetype == "js" ) { //if filename is a external JavaScript file            var fileref = document.createElement( 'script' );            fileref.setAttribute( "type" , "text/javascript" );            fileref.setAttribute( "src" , filename);        }        else if (filetype == "css" ) { //...

Validating Username, password and timestamp in WCF

  Recently I have got an requirement which is to validate username, password and timestamp set in the message header in each call made to WCF. Following is the solution I came Up with.   Validating Username and Password   Step 1: Create a wshttpbinding and add the following configuration. < wsHttpBinding >      < binding name = " wsHttpBinding " closeTimeout = " 00:00:10 " openTimeout = " 00:00:10 " receiveTimeout = " 00:00:10 " sendTimeout = " 00:00:10 " >        < security mode = " Message " >          < message clientCredentialType = " UserName " />        </ security >      </ binding >    </ wsHttpBinding >   Step 2: Create a custom username and password validator as below public class UserValidator : UserNamePasswordValidator    {        public override void Validate( string userName, string password) ...

OData in WebApi 2

  Web API 2 comes with OData query support. It supports the following query options for webAPI client applications to customize the result set returned by the API based on there requirement. Option Description $expand Expands related entities inline. $value Gets the raw value of a property. $filter Filters the results, based on a Boolean condition. $inlinecount Tells the server to include the total count of matching entities in the response. (Useful for server-side paging.) $orderby Sorts the results. $select Selects which properties to include in the response. $skip Skips the first n results. $top Returns only the first n the results.   To use OData queries you need to enable it globally, controller or specific action level. Enable Globally 1. In you MVC project go to App_Start folder 2. There you can find the WebApiConfig.Cs 3. In there add the following code. public static void Register( HttpConfiguration config)     {         ...