Posts

User Impersonation : using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Security.Principal; using System.Text; using System.Threading.Tasks; namespace test12 {     class UserImpersonation : IDisposable     {         [DllImport("advapi32.dll")]         public static extern bool LogonUser(String lpszUserName,             String lpszDomain,             String lpszPassword,             int dwLogonType,             int dwLogonProvider,             ref IntPtr phToken);         [DllImport("kernel32.dll", CharSet = CharSet.Auto)]         public static extern bool CloseHandle(IntPtr handle);         WindowsImpersonationContext wic;  ...
XMLHttpRequest cannot load http://*****/api/***.'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://*****therefore not allowed access. Solution: enable cors on you web api application . Steps:  Goto top right corner of your visual studio and type package manager console. select package manager console and it opens up console at the bottom of vs as error List/output show up generally  step 2: type the following command : Install-Package Microsoft.AspNet.WebApi.Cors it may ask for say yest to all as this package going to add some code and make some changes to application if you are using tfs if may request you to accept the changes and say yes to all . once installation is done you will see warnings in you error list and just by double clicking these error it included the missing references and evrything should be good . step 3: build and see if everything works fine. ...
Create Asp.net Web API 2 : http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
caml query not returning selected value from choice field : so an inverse select ex: if you want to get which are yes or true make it not equal to no or false . NEQ --> no or false of that field <Neq><FieldRef Name='filename' /><Value Type='Boolean'>No</Value></Neq>
Filter results from a data table c# ex: get unique  values of a coloumn , DataView view1 = new DataView(datatable1);                         distinctValues1 = view1.ToTable(true, "user");                         DataRow[] values1 = distinctValues1.Select(" ");                         int numberofitems= values1.Count(); //this gives you count of unique rows you can access info of that unique rows from values1 array .
format date to YYMMDD   . c#  (.net ) DateTime theDate = DateTime.Now.AddDays();                     string thedate = (theDate).ToString("yyMMdd");
.net console application execute as differnet user : or .net  read file as a different user etc :  using (UserImpersonation user = new UserImpersonation(uname, Domain, pass))             {                 if (user.ImpersonateValidUser())                 {                     //write your code to read file or access items etc ..                  } } wehn you run the code you can see if you are successful to login as that user or not .if you are logged it it show old user and impersonating user details . right click on U serImpersonation: and select generate a class : ADD THIS CODE TO THAT GENERATED CLASS FILE : make sure you add inherit from idisposable . class UserImpersonation: IDisposable     {         [DllImport("adva...