Kids, don't try this at home!
Tips & Tricks for C#, ASP.NET and CRM
-
CRM 4 FilteredViews, LINQ & WCF
We decided to use FilteredViews instead of FetchXml for an internal project, but we ran into couple of problems. You can't access data from the FilteredViews using ASP.NET since it runs under NETWORK SERVICE (by default (app pool)), FilteredViews filter the data by Users.
If you set the <identity> settings on the WCF service you'll notice it has no effect, you need to tell WCF to run in asp compatibility mode, check this link for more details.
Impersonation needed for FilteredViews
- EXECUTE AS doesn't work, some forums suggested we enable DB_CHAINING, TRUSTWORTHY & grant NETWORK SERVICE Impersonate for each User, we decided to take a different route since these database changes are unsupported by Microsoft.
- Configuring the Application Pool to run as a different user gave a "Service Unavailable" error, changing the User that runs when an anonymous request comes into IIS didn't seem to work either.
Solution
web.config
<authentication mode="Windows" />
<identity impersonate="true" userName="..." password="..."/>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
</system.serviceModel>
*.svc.cs
Set this attribute on your service class
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
That'll allow you to use FilteredViews in your asp.net application, as you can see there are downsides to this solution. Impersonating username/password is inside the web.config file (unencrypted), only allows us to filter by that user.
Check out LinqtoCRM on codeplex, this tool will be great once all the LINQ funtionality is implemented. -
CRM 4 Outlook Client Installation error
While trying to install CRM 4 Outlook Client on a Vista Business laptop I got an error:
-
Working with Dynamic Controls
Control c = this.wrapper.FindControl("dynamictextbox");
-
Storing ViewState in SQL
<browsers>
-
MPEG Header Reader
A while back I needed to read a mpeg file and retrieve the video/audio information. I didn't want to read the mpeg specification to write one from scratch so after googling around I found a project on sourceforge called mpgtx, it's written in C and has a lot of features. I didn't convert everything in mpgtx to C#, just the bits that read the mpeg header.
Here it is for anyone else that wants to read an mpeg file using C#. -
Upgrade to CRM 4 breaks Exchange web access
After upgrading a system that was running CRM v3 to v4 exchange web access stopped working. Error was "The page you are looking for cannot be found".
To get around this problem without touching the default CRM v4 website this is what I did.
Creating a new HTTP Protocol in Exchange
1. Open Exchange System Manager
2. Expand Administrative Groups -> First Administrative Group -> Servers -> <Your Server> -> Protocols -> HTTP
3. Right click HTTP -> New -> HTTP Virtual Server
You can't run multiple websites on the same port unless they have different host names.
4. Click on Advanced under the IP settings -> select the default entry -> click Modify -> specify a new host name
5. Give this virtual server a name and leave the defaults and click OK.
6. Expand Exchange Virtual Server (first one under HTTP)
7. Right click Exadmin -> Properties, make a note of the properties and their values
8. Right click the new virtual server you just created -> New -> Virtual Directory -> Fill in the properties/values you noted from step 7
9. Repeat these steps for Exchange, Microsoft-Server-ActiveSync, OMA, Public
Tweaking IIS
We need to tweak couple of things in IIS to make this work with active sync.
1. Open IIS Manager
2. Expand <Your Server> -> Web Sites -> <Newly created Exchange Virtual Server>
3. Right click Exchange -> All Tasks -> Save Configuration File -> Save it somewhere
4. Right click <Newly created Exchange Virtual Server> -> New -> Virtual Directory (from file)
5. Select the file you saved in step 3
6. Click Read File
7. Select the first entry (Exchange)
8. Click OK -> Select Create new virtual directory
As far as I know step 9 is only required with SBS
9. "exchange-oma" should be the name of the new virtual directory
10. Click OK
That's it, you'll be able to access Exchange Web using the new host name.