Jun 10th, 2009 | No Comments

Here is the little code that you can use to impersonate any user in sharepoint. This will code will pretend that you are logged in as the user who is impersonated and will be allowed access to all the features and inherits all the rights for that person. This is mainly used to do something for which the impersonating person has rights and you other user do not have rights.

SPWeb web = SPContext.Current.Web.Site.OpenWeb();
SPUser user = web.AllUsers[username];
SPUserToken userToken = user.UserToken;
SPSite site = new SPSite(SPContext.Current.Web.Site.Url.ToString(), userToken);
web = site.OpenWeb();

Here username is the name username of the user who you want to impersonate as.

Hope this helps :)

Written by Ajay Matharu

June 10th, 2009 at 10:42 am

Apr 20th, 2009 | 1 Comment

To add an unknown extension in IIS for your IIS to detect that extension perform the following steps.

To define a MIME type for a specific extension, follow these steps:

  1. Open the IIS Microsoft Management Console (MMC), right-click the local computer name, and then click Properties.
  2. Click MIME Types.
  3. Click New.
  4. In the Extension box, type the file name extension that you want (for example, .pdb).
  5. In the MIME Type box, type application/octet-stream.
  6. Apply the new settings. Note that you must restart the World Wide Web Publishing Service or wait for the worker process to recycle for the changes to take effect. In this example, IIS now serves files with the .pdb extension.

Written by Ajay Matharu

April 20th, 2009 at 7:54 pm