Category Archives: Development – SP
401 Access Denied error on reading a MOSS document from web part/.NET application
I am working on a web part that reads an XML template (applies to any files) from a “Document List” on MOSS. Here is the code:
Pitt is the hostname when setting up the “Web Application” in MOSS, in this case the web part is trying to connect to itself (localhost, pitt).
When the Web Part comes up, it throws an 401 Exception on the xmlDocument.Load(). I thought it was something to do with permission and should be very easy, ended up spending more than 2 days to figure this out.
Configuration:
Windows 2003 Enterprise with SP2, MOSS 2007, Visual Studio 2008, .NET 3.5 SP1
What I have tried:
1. Using “System.Net.NetworkCredential” to hardcode the username/password for the resolver, still got 401 error
2. Checked the Identity Application Pool, MOSS Service, Farm Administrator, Web Application Policy (Central Admin), Site Collection administrator, all permission related area, etc.
3. Deleted the MOSS Web Application and re-created it, didn’t help
Symptoms:
1. Internet Explorer on the MOSS server worked fine (connecting to pitt, locally), and was able to get the XML document (IIS Log showed proper credential was passed). However if you take a look closely, you can see first 2 attempts failed (401 error), however 3rd time the credential was passed (alpha/rini):
2. Web Part running locally, gets 401 error (On the IIS Log, the Credential was NOT even being passed, it was missing from the Http Request!!!!)
Problem Isolation
To isolate the problem, I wrote a very simple Windows .NET application.
Extremely Strange:
When Windows Application ran locally, get 401 Access Denied error:
When Windows Application ran remotely from another computer on the LAN, it worked ???
Workaround
After spending so much time, I came up with a workaround:
1. Delete the HOST header on IIS for your MOSS web application
2. In the code, do not use the host name. Use “localhost” instead:

This works for both web part and windows application!
Final Solution
With help from the coworkers in our team to solve this weird problem, no one had a clue why this was happening. Finally one of our team members recalled that there was similar authentication issue on production server a while ago and our Operation group changed one registry and fixed it. This lead us to a new keyword, called “Registry”. Google on this important keyword, BINGO! Found the Microsoft article: http://support.microsoft.com/kb/896861
Following the article and edited the registry, and it FIXED the problem!!!!
Further reading the article, this explains why my workaround worked, because HOST NAME did not match with the MACHINE NAME! It was a new security feature being introducted in Windows 2003 Service Pack !! Damn it.
MOSS 2007 – Custom site template is missing after upgrade from 2003
Problem: After upgraded to MOSS 2007 and when you try to create a SubSite, you only see the Microsoft standard templates i.e. (Collaboration, Meetings, Enterprise and Publishing). How can you create a new subsite using your custom template from MOSS 2003?
Solution:
1. Open a SubSite in MOSS 2007 which has already been upgraded.
2. Go to “Site Settings” of that sub site
3. Your URL should look like this:
http://server/DirectoryName/SubSiteName/_layouts/Settings.aspx
4. Manually edit the URL
http://server/DirectoryName/SubSiteName/_layouts/savetmpl.aspx
5. Save it on the server in the template gallery
Site Template Gallery URL (very useful):
http://server/_catalogs/wt/Forms/Common.aspx
6. Go and create a New Site, you should see your custom template:

7. Your new site should have the custom template.
Reference and Credit:
The SharePoint Farmer’s Almanac
MOSS 2007 – Missing Site template after upgrade from 2003
Problem: The site template is missing after upgrading from SP 2003 to MOSS 2007, there is an [X] missing JPG and there is no template to choose from.

Solution: Goto the site setting of your subsite and choose “Subsites can use any site template”

This should fix the problem.
Microsoft Sharepoint Tricks for Reference
- Manage Web Part Gallery
By adding “?contents=1” at the end of the URL, we can go directly to manage the Web parts which are associated with the specific page:
http://server/default.aspx?contents=1
http://server/search.aspx?contents=1
http://server/MySite/default.aspx?contents=1
- Modify A Page without ‘Edit Page’
Sharepoint does not always provide you with the “Edit Page” link on left navigation on every single page, there are pages you want to customize but you can’t. By adding “?Mode=Edit&PageView=Shared” at the end of the URL, it will force Sharepoint to show the “Modify Shared Page” on the Top-Right hand corner. Then you can Add/Design the page whatever you want. For example, you won’t find the “Edit Page” link for search.aspx. But you can use this to bypass that:
http://server/search.aspx?Mode=Edit&PageView=Shared





