Fix Access Denied Errors in SharePoint Search

As of late, I haven't been doing much in the way of programming. Instead I've been working with our SharePoint install at work (setting up InfoPath, Excel Services, etc.). One of the issues that I had to tackle was the fact that the crawler stopped working. The account it was using had the proper rights, the service itself was set up correctly, etc. In fact it was working at one point and there hadn't been any changes to the settings. So why the sudden issue?

Well we have one server that acts as the search service and the site itself. As such the search service is basically doing a crawl on the local host (and we're using a fully qualified domain name). This apparently doesn't work due to a loop back check that windows does in order to protect itself from reflection attacks (you can read about it here). In otherwords, it's by design and shouldn't be messed with on public facing servers. However in my case, this server is completely behind the firewall. So how do we disable the loopback check and get our search working? Simple, follow these steps (which are described in the link above):

  1. Click Start, then Run (or if you're on 2008, just click on the search box), and type regedit, and then click OK.
  2. In Registry Editor, locate and click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
  3. Right-click Lsa->New->DWORD Value.
  4. Change the name of the new key to DisableLoopbackCheck.
  5. Right-click DisableLoopbackCheck, and click Modify.
  6. In the Value data box, type 1, and click OK.
  7. Quit Registry Editor and restart your computer.
That's it. Once the computer restarts you should be able to start the crawl and have it work. Hopefully this helps you out. So try it out, leave feedback, and happy coding.
kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 5/20/2009 at 8:53 AM
Tags: , , ,
Categories: General
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Getting Public Key and Public Key Token of a DLL, the Easy Way

This one has no code but just explains something that has been annoying me and my solution to it. Anyway, I've been doing a lot of SharePoint development at work lately. To be honest, it's not that different from normal ASP.Net development (which shouldn't be shocking considering it's based off of ASP.Net) but the one thing that has annoyed me to no end is the constant creation of strong name assemblies... Which basically just means that I have to sign the assembly. That's easy, you just go into the properties of the project, go down to signing, click on Sign the Assembly, and create a new key. That's all there is to it.

Now figuring out what the public key/public key token for the newly signed project is, now that's an annoyance. In order to figure it out you need to use a program called sn. It can be found at C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe. Now going to that location, running it each time you create a new DLL is annoying... So I created a simple entry in Visual Studio to run the app for me:

  1. In Visual Studio go to Tools->External Tools
  2. Click Add
  3. Enter in the following:
    1. Title: Get Public Key
    2. Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe (or where ever the sn program is found on your system)
    3. Arguments: -Tp "$(TargetPath)"
  4. Click OK
And that's it. Now whenever you click on the option in the Tools menu, it will pull up the public key information for the DLL. So hopefully this helps you out. So leave feedback and happy coding.
kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 3/12/2009 at 11:07 AM
Tags: , , ,
Categories: General
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Creating a SharePoint Site Programmatically

I've been working with SharePoint at work... Working through the interface is simple, but I've been tasked with coming up with another side site that will allow us to remotely configure the server... Don't ask. Anyway, while attempting to discover how to programmatically create a site collection, I stumbled upon how to create a site:

        if (Request.HttpMethod == "POST")
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite("http://SITE"))
                {
                    SPWebApplication webapp = site.WebApplication;
                    SPWeb web = site.OpenWeb();
                    web.AllowUnsafeUpdates = true;
                    web.Site.AllowUnsafeUpdates = true;
                    web.Webs.Add("Name", "name site", "", 1033, "STS#0", false, false);
                    web.Dispose();
                }
            });
        }

Note that the code above is going to need you to modify it a bit. But you need to first include a reference to Windows Sharepoint Services, add:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;

Then the code above will still crash on you... You're going to need to also make sure that in the web.config file that you set it to windows authentication and turn on impersonation... Oh and you need to run this as someone who has access to the database/is a farm administrator... But that's what the impersonation is for. Then and only then will it MAYBE run. You may have to sacrifice a goat to Microsoft... It seemed to work for me... Oh and if you want, you can modify the theme (STS#0 is just the default theme) but I've had a couple issues with setting some of their defaults for some reason. Anyway, hopefully my pain helps someone else out, so try it out, leave feedback, and happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 3/6/2009 at 9:53 AM
Tags: ,
Categories: C# | Web Design
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed