Think Therefore

Muse, contemplate or ponder. Often best served with a drink. All I know is the world's a wonder… therefore I think.

Archive for July, 2011

Automatic Windows authentication in Firefox

in Web Development

By default, Internet Explorer is the only browser that can pass your Windows login credentials onto web sites. In fact, Firefox doesn’t even give you the option of remembering your login details; you have to re-enter them every session.

However, there are a few tweaks that can be made to make both IE and Firefox use your Windows login credentials for certain sites:

  1. Open up regedit.
  2. Locate registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa.
  3. Add a new DWORD Value called DisableLoopbackCheck and set the value to 1.

Then in Firefox:

  1. Browse to about:config.
  2. Enter uris into the filter box.
  3. Enter a comma separated list of you sites into the three preferences* that are shown. E.g. local-1,local-2

If IE still/now shows a prompt after making these changes:

  1. Go to Tools > Options.
  2. Select the Security tab.
  3. Select Local intranet.
  4. Click Sites.
  5. Uncheck the ‘Automatically detect intranet network’ setting.

* The three Firefox prefs should be ‘network.automatic-ntlm-auth.trusted-uris’, ‘network.negotiate-auth.delegation-uris’ and ‘network.negotiate-auth.trusted-uris’.

Fixing orphaned SQL Server users

in Web Development

If you transfer a SQL Server database from one machine to another then you’re pretty much guaranteed to break any users associated with it. This is because the IDs for the linked logins are unique to each machine.

There is, however, a handy stored procedure that can help you restore the orphaned user: sp_change_users_login.

All you need to do is run the following command against the database in question, substituting [user_name] for the name of the user you want to restore:

exec sp_change_users_login 'auto_fix', '[user_name]';

Switching indenting formats in Visual Studio

in Web Development

The following is a simple macro that will allow you to switch indenting formats within Visual Studio. It’s only been tested in Visual Studio 2008 but it will allow you to quickly toggle between preserving tabs with a 2 space tab/indent (default) and preserving spaces with a 4 space tab/indent (alternative).

Once added you can then manually run the individual functions (DefaultIndenting or AltIndenting) or bind them to some hot keys.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Indenting

    Private Sub Toggle(ByVal bDefault As Boolean)
        Dim props As EnvDTE.Properties
        Dim ts As EnvDTE.Property
        Dim ins As EnvDTE.Property
        Dim tabs As EnvDTE.Property

        props = DTE.Properties("TextEditor", "AllLanguages")

        ts = props.Item("TabSize")
        ins = props.Item("IndentSize")
        tabs = props.Item("InsertTabs")

        If bDefault = True Then
            tabs.Value = True
            ts.Value = 2
            ins.Value = 2
        Else
            tabs.Value = False
            ts.Value = 4
            ins.Value = 4
        End If
    End Sub

    Sub DefaultIndenting()
        Toggle(True)
    End Sub

    Sub AltIndenting()
        Toggle(False)
    End Sub

End Module