Skip to main content

Posts

Showing posts from June, 2013

Add Remove Items from one ListBox to Another

In this post going to share to code-sample for the Add and Remove  items form one ListBox to another ListBox  in asp.net with c#. Some time before, i have needed to add and remove to user role as per your requirements and update the user role in the database.  Table of Constants 1. In the 1st step, code-sample for aspx page. 2. In the 2nd step, code-sample for C# (.cs page). In the 1st step , .aspx code-sample < asp : Content ID ="HeaderContent" runat ="server" ContentPlaceHolderID ="HeadContent">      < asp : ListBox runat ="server" ID ="listBoxRoles1"    SelectionMode =" Multiple " ></ asp : ListBox >         < asp : Button ID ="btn_Add" runat ="server" Text ="Add" onclick ="btn_Add_Click" />      < asp : Button ID ="btn_Remove" runat ="server" Text ="Remove" onclick ="btn_Remove_Click"

get ip address client in wcf service

Hi, i'm going to explain, how to allow some specific IP address to access my WCF Services and in this example, we need a xml file where we define to IPAddress to allow some specific address otherwise deny.   Example:    public IPAddressFilter   {         try             {                 OperationContext context = OperationContext.Current;                 MessageProperties msgProperties = context.IncomingMessageProperties;                 RemoteEndpointMessageProperty endpointPropertes = msgProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;                 string IPAddress = endpointPropertes.Address;                     if (!GetIP_From_Config_File(IPAddress))                     {                         HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();                         responseProperty.StatusCode = (System.Net.HttpStatusCode)401;                         messageProperties["httpResponse"] = responseP

json datetime format in javascript jquery

Hello everyone, I'm going to share the code-sample for  DateTime format in jquery JSON In the 1st step , we get the DateTime using javascript, sample code as  given below.   var createDate = new Date().getTime(); In the 2nd step , we create request body for input-data, sample code as given below. var requestBody = {                                  user: {                                             Id: 9,                                             CreatedDate: '/Date(' + createDate + ')/'                                         }                               };  In the 3rd step , we convert to request body to JSON using JSON.stringify() code sample as given below. var JSONrequestBody=JSON.stringify(requestBody); In the 4th step , we write to authenticate to services and call to JSON request.       var username = "user";     var password = "user@123";     var doAuthenticate = function (uid, pwd) {         var token

valid json request body in jquery json

valid json request body in jquery json     var uid= "user";     var pwd= "user@123";     var doAuthenticate = function (uid, pwd) {         var token = user + ':' + password;         var hashCode = btoa(token);         return  'Basic ' + hashCode;      };     var createDate = new Date().getTime();     var requestBody = { user: { Id: 9, CreatedDate: '/Date(' + createDate + ')/'} };     var JSONrequestBody=JSON.stringify(requestBody);         $.ajax({             url: ' http://aspdotnetblogspot.blogspot.in/2013/06/authentication-on-wcf-rest-service-json.html ',             type: 'POST',             data: JSONrequestBody,             beforeSend: function (xhr) {                 xhr.setRequestHeader("Authorization", doAuthenticate(uid, pwd));             },             async: runInBackground,             contentType: 'application/json',             success: successHandler,    

Options dropdownlist binding in knockoutjs

KnockoutJS Options Bindings using mvc 4 jquery This is a simple example , to bind the options or dropdownlis in knockout js . In the 1st step , write the view code which are give below: <select data-bind="options: subscriptionsList, value:ID, optionsText:'FriendlyName' "></select> In the 2nd step , write the viewModel code and bind to viewModel code within document dot ready function. <script type="text/javascript">     function subscription(id, name) {         var self = this;         self.ID = ko.observable(id);         self.FriendlyName = ko.observable(name);     }     function ViewModel() {         var self = this;         self.ID = ko.observable();         self.subscriptionsList = ko.observableArray();         var subscriptions = [             {             ID: '1',             FriendlyName: 'Friendly 1'             },             {             ID: '2',             FriendlyName: 'Friendly 2'

Authentication on a WCF REST Service using JSON Request

Hello everyone,  I am going to share the code sample how re st service  authenticate using  JSON Request. Table of Contents First added to request headers for rest service authenticate. Encrypt the username and password and added in the heder. In Step 1 Need to add request headers to authenticate a wcf rest services using json request response. i.e. beforeSend: function (xhr)  {    xhr.setRequestHeader( "UserRoleId" , "1" );    xhr.setRequestHeader( 'Authorization Basic ' , authenticatedByRequestHeader(username, pwd)); } In the 2nd Step Need to encrypt username and password and sent with heeder responses. i.e. var username = "validate@gmail.com" ; var pwd = "validate" ; function authenticatedByRequestHeader(username, pwd)  {    var token =  username  + ':' + pwd;    var hashpwd = btoa(token);    return hashpwd; } Example for Authenticate REST WCF Services using JSON AJAX <