04.1.10

Windows Authentication in Firefox

Many .NET based web apps and enterprise web apps use Windows authentication so you don’t have to ever login – your browser automatically uses your windows credentials. For a long time I assumed this only worked in Internet Explorer but I recently found that Firefox will do this too! All you need to do is tell it which websites are allowed to use the windows credentials and you all set. Here are the steps:

  1. Visit about:config in Firefox.
  2. You might need to click the “I’ll be careful, I promise!” button to continue.
  3. Use the filter at the top to find the following three properties (one at a time)
    • network.negotiate-auth.trusted-uris
    • network.negotiate-auth.delegation-uris
    • network.automatic-ntlm-auth.trusted-uris
  4. Double click the property and add the URL of the site you are trying to use Windows authentication with to the value. If you have several sites, separate them with commas.

Thats it!

You should follow me on twitter @dwradcliffe.

| Posted in .NET, Windows | No Comments »
02.23.10

UpdateModel requires properties

I was working on a feature at work this week on a ASP MVC project. I was attempting to use UpdateModel to update an object retrieved from the database with values from the POST. If you aren’t familiar with it, ASP MVC has a “magic method” to map these POST values to an object. One simply needs to call

UpdateModel(myObjectFromDatabase);

and the new values will be changed on the object.

That is all fine and dandy unless it doesn’t work. I had checked everything. I could verify that the values were in the Request header. I could verify that UpdateModel was called and did not fail. The values simply were not updated.

I finally found the key (thanks to my supervisor). The object I was updating had a mix of auto-properties and fields. Apparently, UpdateModel will only update properties. A quick change from a field to an auto-property and everything worked as it should. Thanks Aaron!

02.20.10

Clean Phone Numbers

I’ve been working with a lot of person type data recently at work and I’m using data from multiple sources. Not just two databases but two separate systems with similar and yet incompatible data. One of the biggest messes was the phone numbers. I need to convert a phone number from a completely un-normalized format to a very strict format. I’m no regular expression genius so thankfully a quick Google search produced a nice PHP method of doing pretty much exactly what I was looking for. (http://cnanney.com/journal/code/cleaning-phone-numbers-with-regex/) I took that method and re-wrote it in C# and tweaked it a little for my application. I’m sure this isn’t the absolute best way to do this but it works for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const string pattern = @"\D*\(?(\d{3})?\)?\D*(\d{3})\D*(\d{4})\D*(\d{1,8})?";
string num, ext;
var matches = new Regex(pattern).Match(number).Groups;
if (matches.Count > 0)
{
if (matches[3].Length > 0)
{
if (matches[1].Length > 0)
{
num = "(" + matches[1].Value + ") " + matches[2].Value + "-" + matches[3].Value;
}
else
{
num = matches[2].Value + "-" + matches[3].Value;
}
}
else
{
num = null;
}
ext = matches[4].Length > 0 ? matches[4].Value : null;
}
else
{
num = null;
ext = null;
}