Friday, December 10, 2010

ASP.NET Impersonation and "Could Not Load File or Assembly" Error

When setting up an ASP.NET site on a server if you are using impersonation on the web site, typically set via the setting, you need to ensure that the user account being impersonated has access to the server. Typically this means you need to add that user account to the Users or Administrators group on the server. 

If you do have the appropriate permissions granted to the impersonating user, you will most likely receive an error message similar to "Could not load file or assembly or one of its dependencies. Access is denied". This is because the account does not have access to write to the c:\Windows\Microsoft.Net\Framework\\Temporary ASP.NET Files" directory.

I have run into this issue numerous times and keep forgetting how to fix, so I finally decided to post it here, in hopes that I will find it the next time and hoepfully help someone else out as well.

Thursday, December 9, 2010

Improving Your Brain Power

Last year my kids received a Nintendo DS for Christmas and my wife purchased Brain Age: Train Your Brain in Minutes a Day! We both really enjoyed the challenge and the kids were actually pretty good at it too. The other day I stumbled upon a website that provides similar (and probably better) brain training. The site is Lumosity and it is a great collection of brain training and grain games that can lead to:
  • Clearer and quicker thinking
  • Improved memory for names, numbers, directions, etc.
  • Increased alertness and awareness
  • Elevated mood
  • Better concentration at work or while driving
Right now they are offering a free 7 day trial of their subscription service. I highly recommend checking it out.

Tuesday, December 7, 2010

VB.NET Sort Comparer

I found myself needing to sort Generic List of custom objects, in this case a list of the last seen users on a website. I wanted to sort the list by Date Last Seen Descending. I am primarily a C# developer, so I knew how to do this with a Delegate method. But, I am using an older version of VB and Delegates are not available. So I headed over to StackOverflow and found this great question, How to Sort A System.Collection.Generic.List in VB.NET. After looking at this article I created the following code:

public class UserLastSeen
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime LastSeen { get; set;}
}


public class UserLastSeenSorter
{
public void GetSortedList()
{
List(Of UserLastSeen) userList = GetUserList()
userList.Sort(AddressOf UserLastSeenDescendingComparer)
}
private Function UserLastSeenDescendingComparer(ByVal user1 As UserLastSeen, _ ByVal user2 as UserLastSeen) As Integer
{
Return user2.LastSeen.CompareTo(user1.LastSeen)
}
}

This worked great and was very easy.

Wednesday, November 17, 2010

Issues with Windows Update KB2160841

If you experience issues with installing Microsoft Update KB2160841 on your machine, please try following the steps in MS Answers forum post - Can't Install KB2160841 to Repair the .NET Framework Client Profile.

I was having this issue on multiple Windows 2008 servers and repairing the .NET Framework 4 Client install worked every time.


Good Advice for Writing Well

Saw a link to How to Write Good come across on Twitter the other day. These are really good tips and advice to follow, in my opinion. Considering that today almost everyone writes email or text messages every day, you should read these rules and learn to follow them. I know that I am going to attempt to do that, starting now.


Tuesday, November 9, 2010

Too Many Encodings

Ran into an issue today where we were running too many encodings (url and html) on a string before I reached its final destination. This was causing some really weird behavior and was a little difficult to track down. But after some digging it was pretty clear to see what was happening…

Basically if you have a string like “Your $$$$$” that you wanted to search against. (In this case we want to keep the quotes as they are a search hint to find this exact phrase), you would want to url encode this to go across the wire to our REST based Solr search server.

However, we were applying an errant Html Encoding against this string before sending it on to the Solr server via SolrNet which was in turn performing the Url Encoding on the Html Encoded value. However, that really did not change the value.

Once I removed the extra Html Encoding things were back to working as expected and I learned a valuable lesson about encodings…

Here is an example:

String: “Your $$$$$”

Url Encoded: %22Your%2B%24%24%24%24%24%22

Html Encoded: %26quot%3BYour+%24%24%24%24%24%26quot%3B

While these look very similar they are no the same and managed to produce some very strange results for us as we ended performing searches on phrases like “quot” and “;”.

Friday, September 10, 2010

Debugging Drupal with Eclipse on Mac OS

I have been developing with Drupal for a while now, but had neglected to setup my Eclipse development environment for debugging my Drupal site. I am running MAMP 1.9 locally for my development, so I started following the instructions on the Drupal site for Configuring Eclipse for Remote Debugging with Zend. That got me part of the way there… but not fully there.

I ended up relying on the following articles and video to finally get it all working.

The key takeaways for getting this working were to download the Eclipse PDT and watch out for the superfluous zend_extension setting in the php.ini file.

Now that I am able to debug my Drupal site, my module development just got a whole lot easier!

Thursday, August 5, 2010

Solr DataImportHandler and OData Service Issue

This week I was working on a proof of concept for indexing data from a SQL database with Solr. I had done something similar with xml files using some .NET code to read the xml files into a document class that I then inserted into Solr using the excellent SolrNet library. However, for this, I wanted to try out the Solr DataImportHandler (DIH), since this was a pretty straight forward table to index mapping. So I read up on using the UrlDataSource Import Handler in Solr and set about creating my OData Service to expose the data. I was able to create my OData service pretty quickly and then I setup the DIH following the steps at SolrWiki. However, when I attempted to call the OData Service from the DIH, it kept generating an error accessing the OData url. I was getting an HTTP 400 error. This was really strange, because I was able to access the OData Service without any issues from the browser. It was only when I use the DIH that I had this problem. With some help from another colleague, it was determined that the issue was in the http accept headers that were being sent by the DIH call to the OData service. The server was generating the error “Media type requires a ‘/’ character”

The Accept Header being passed is:

text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

The issue is last two media types “*; q=.2, */*; q=.2” - the OData services do not recognize the relative quality factor as found the Http Header Field Definitions in RFC 2616 – Section 14. I even tried connecting to the OData Northwind Sample Service, but had the same issue.

So in order to work around this issue, I created the following HttpModule to workaround the issue by removing these two bad entries.

using System;
using System.Collections.Generic;
using System.Web;


namespace SolrIISModules
{
public class AcceptFilter : IHttpModule
{
private const string ACCEPTHEADER = "HTTP_ACCEPT";
private const string BADSOLRACCEPT = "*/*; q=.2";

public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
}

private static void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
var application = sender as HttpApplication;
if (application == null) return;

var request = application.Context.Request;
if (string.IsNullOrEmpty(request[ACCEPTHEADER])) return;
var acceptValues = request[ACCEPTHEADER].Split(',');
var filteredValues = new List<string>();
foreach (var value in acceptValues)
{
if (!value.Contains("/")) continue;
if (IsBadSolrValue(value))
{
//only add the */* back in, otherwise an http 415 error will be generated.
filteredValues.Add("*/*");
continue;
}
filteredValues.Add(value);
}

application.Context.Request.Headers.Set("accept", String.Join(",", filteredValues.ToArray()));
}

private static bool IsBadSolrValue(string acceptValue)
{
return string.Compare(acceptValue.Trim(), BADSOLRACCEPT, true) == 0;
}

public void Dispose()
{
}
}
}




Now I just enable this module on my IIS website that is hosting the OData Service and I am able to get my DIH working as expected. I had tested this with an OData service hosted in both ASP.NET Webforms and ASP.NET MVC websites.

Tuesday, March 16, 2010

XML in Google Chrome

Have you ever tried to view an XML stream in Google Chrome and expected to see the nicely formatted XML document like you get in Internet Explorer... I know I sure did and was surprised when I did not see it. Do not despair, as there is a great Extension for Chrome - XML Tree by Alan Stroop. This was a life saver, as I love to use Chrome and wanted the same experience. If you need/want to look at XML using Chrome, then I would recommend getting this Extension.

Friday, February 12, 2010

Disable Logging for Folders/Files in IIS 7

Since turning off logging for IIS 7 folders or files is not as straight forward (or intuitive) as it is in IIS 6. I thought I would post the steps here. For IIS 6 you can follow the instructions in this MS Knowledge Base Article.

Disable IIS logging for a folder

  • Open up IIS 7 Manager
  • Expand the website in the left pane to see the folder structure.
  • Click on the folder name to select it.

               image

  • Double click on the Logging entry in the folder home page.

             image

  • Click the Disable link under Actions on the right pane.

            image

Disable IIS Logging for a file

The steps for a file are almost identical for an individual file.

  • After you select the folder where the file resides, click the Content View at the bottom of the middle pane to see all the contents of the folder.

               image

  • Select the file that you want, then click Switch to Features view under Actions on the right pane.

                image

  • Then follow same last two steps as above to turn off Logging for that file.

Local Version Control and Backup

So I finally started using SVN to version control all of my local projects via VisualSVN and using the ankhSVN plug-in for Visual Studio. I have also setup my Repository directory to be in my local Dropbox folder so that I get automatic backup. Here are some useful articles if you want to start doing this yourself. You might also want to install TortiseSVN so that you can manage other files outside of Visual Studio.

Wednesday, February 10, 2010

Remote IIS 7 Admin stopped working after Installing .NET 4

I ran into a situation the other day where I was unable to connect to a remotely administer an IIS 7 (Windows 2008) server after installing the .NET 4 Framework. After some checking the steps that I used to setup the server in this blog post, I figured out that when .NET 4 installed it turned off IIS 7 Management Service and unchecked the Enable Remote Connections options on the service.

image

Once I checked this option again and restarted the service, everything was working again. Strange that installing .NET 4 would have done that… oh well, now I know.

Hope this helps someone else.

Friday, January 15, 2010

jQuery 1.4

The newest version, 1.4 of jQuery was released yesterday. You can download it and watch the Q&A about the release at the official homepage jquery14.com. Also I found this great list of the 15 new features you must know.

Go check it out…

Monday, January 4, 2010

Visual Studio 2008 and 2010 Project File Differences

I was working today on converting one of our larger web applications over to a Visual Studio 2010 project. Once I had converted the web application and related custom assemblies, I was curious to see what differences there were in the project files. Please note that I am referring to the actual .csproj (for a C# project) files, which are actually just XML files.

Here are the differences that I found:

  • <Project> node – ToolsVersion attribute value jumped to 4.0
  • Added the following new elements under the <PropertyGroup> element.
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>




  • Added the following new element under each <PropertyGroup> element for the defined builds – (Debug and Release in my case).
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>





  • Added the following new <ItemGroup>






  <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>



So it does not look like the differences are all that major, just adding some new elements for the most part. This will be useful if I ever need to switch a project file back and forth between the two VS versions.