Check the Organization Name your passing
If your using the 2007 Web Service end point make sure you know what Organization name you are setting.
This can be a good cause for authentication errors on invoking a service request. One that you might run into is where the user is authenticated to one org and you request another via the Organization property on the authentication token. The error you might see might look like the following
"0x80040203 The organization id of the user being verified does not match the organization id of the execution context passed to VerifyUser"
That error is pretty clear, but not all of them are. That one occurred when I was using CrmImpersonator connected to org A, but passed org B on a request. Read Philip Richardson's post on CrmImpersonator if that's new to you here. I will be blogging about it in more detail later on some ways to mask a lot of the Authentication process and make it easier.
I have also seen errors manifest themselves as a Http 401 error so if you are getting a 401 error on making a request - double check your organization name. A blank org name could be the cause as well.
If your writing an ASP.NET application, getting the Org name still isn't as clean as I'd like it to be - I'm still in search of a best practice here so if you find one drop me a comment! Ideally it would just be in the Context.Items (Placed by the CRM HttpModule) or something to make it easy to grab without parsing the url or trying to always pass it to requests. Maybe ExtractCrmAuthenticationToken could pull it also in the future when it gives you the token - but what's the best practice for now?

Reader Comments (1)
I created a very simple one page web application and deployed it to a MS CRM 4.0 website
within its own virtual directory. But each time I try to access my custom web page from
a link that I placed in the Sitemap I get the following error.
"Could not load type 'TitanWebTest._Default'"
Is is basically trying to access,
http://crmproduction:5555/crmProductionAlpha/TitanWebTestInstaller/Default.aspx
Where "crmProductionAlpha" is an organisation and not the default. I believe it needs
to be done this way as I cannot see otherwise how else to work out what organisation
a user is trying to access under a multi-tentant setup.
I have added the httpModules clear entry to my web applications web.config file as per the
following blog post,
(http://blogs.msdn.com/cesardelatorre/archive/2007/11/14/how-to-deploy-your-own-asp-net-application-within-the-same-dynamics-crm-4-0-iis-website.aspx)
and even put the "microsoft.crm.dll" (MS CRM HttpModules) in my web applications folder as per
lots of other blog posts about general asp.net issues with removing http modules.
Using Trace.axd I can see it is trying to access a location of the physical disk that does
not exist so it looks like the http module is still kicking in somehow.
Any advice \ info would be much appreciated.
John