WebMasterSam

.Net, SEO, Dynamics CRM, AdSense/AdWords, Dating sites, Silverlight, Web hosting and more
PPC management, Online Marketing, Search Marketing, SEO, Website development - dotmedias.com

About me

I'm an IT consultant working primarily with the .Net Framework as a developper and architect. I also work on my own on my personnal dating websites. I've been developping websites since 2000.

If you like what I do, feel free to support me

PayPal - The safer, easier way to pay online!

Bookmark

Bookmark and Share

Sponsored links

Amazon hot deals

Computer releases

Last comments

None

Changing Microsoft CRM Dynamics 4.0 Encoding

Recently I worked on a project involving Microsoft CRM Dynamics 4.0 and because the application was in french we decided to change the encoding from UTF-8 to ISO-8859-1 which is quite simple to do but we ended up with a lot of problems...

If you change the encoding of the CRM in the web.config (globalization tag), CRM will then start to show you weird things (horrible characters) instead of accents. The reason is simple, if you convert a text (containing accents) from an encoding like ISO-8859-1 (or Windows-1252) to URF-8 all the accents will be replaced with fucked up characters, leaving normal non-accentuated characters intact.

I discovered that CRM seems to have parts that are always running under UTF-8 instead of following the encoding in the web.config file, so this cause a constant-encoding-converting-glitch. I did not found a solution to solve those CRM glitches so I decided to come back to default CRM encoding: UTF-8.

Beeing in UTF-8 causes convertion problems to the files I add to the CRM (.js - JavaScript). Because my files I create are in Windows-1252 (default), when CRM flush them to the client, they get "converted" and so the accents are beeing mashed up, this causing IE to not load those .js files. The only solution for this is to manualy change the encoding of the .js files to UTF-8 so that they don't get converted automatically.

Conclusion

Never change the CRM encoding; let it to UTF-8 and adapt your stuff.

Don't leave <compilation debug=true /> in production

Because you want your web application to run fast and safely, you don't want to leave to "debug=true" switch on. If you do so, the following things will happen :

Compilation will take longer

Because every .Net DLL must be compiled to be machine specific (at runtime), if you leave debug=true it will take longer because the .Net Framework has to compile more stuff for debugging purpose

Your application will run slower

For the same reason, if your DLLs are in debug mode, they have more stuff for debugging purpose so your code will run slower. Also, it will take more memory, which indeed will help your application run slower.

Everything served by WebResource.axd will not be cached

So this can be bandwith consuming because there is many things that are served by WebResource.axd, even if you don't explicitly use this feature.

----------------------------------------------------

So, what to do if you want to be sure you don't accidently leave a debug=true on your production server ? Just add a "<deployment retail=”true”/>" (system.web section) in your machine.config. This will disable the ability to use the debug mode for all applications running on your server.

Posted: Jul 06 2009, 15:03 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to take an ASP.NET 2.0 Application Offline

If you own or manage ASP.Net 2.0 websites, you will like this not very-known feature called the App_Offline.htm.

When you want to take offline an application, you only have to create a small App_Offline.htm and place it at the root of your web application. IIS will automatically detect it and return its content everytime a request is made to this web application (whatever the asked file is). Internally what IIS does is to kill the application domain of the web application.

When you're done updating your website, just delete the file and IIS will start a new application domain with your update content.

This feature is cool but sometimes your users may not see the content of the file if their browser (IE) is showing "Friendly HTTP errors". IE shows you friendly HTTP errors when the size of the response is less than 512ko, so add content to your file so every user will see the page correctly instead of the "friendly" page. Personnaly I don't know what is friendly in "The page cannot be displayed" !

Posted: Jul 06 2009, 13:56 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Solution for "The server committed a protocol violation: Section=ResponseStatusLine"

If you get an error like "The server committed a protocol violation", you may have some of the following problem (which can be solved by one of the provided solution as well).

Unsafe header parsing

Unsafe header parsing is an option you can turn on on your ASP.Net website (in the web.config) to allow the framework to parse responses. But what is an unsafe header ? It is a header in which the keys contains one or more spaces (that is not allowed in the HTTP 1.1 specifications).

The common case is having a space in the "content-length" header key. The server actually returns a "content length" key, which, assuming no spaces are allowed, is considered as an attack vector (HTTP response split attack), thus, triggering a "HTTP protocol violation error" exception.

To allow the parsing of unsafe headers, add the following to your web.config :


<system.net>
   <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
   </settings>
</system.net>

You forgot to allow HttpGet and/or HttpPost on your web.config

If you call a WebService, you must accept the HttpGet and/or HttpPost protocols in your web.config (they are disabled by default).

So add the following to your web.config file :


<configuration>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
  </system.web>
</configuration>

You're using Skype

If you use Skype, make sure to uncheck the option for using port 80 and 443.

None of the above: find it yourself

If this has not helped, use the following links to help you find the answer :

Configure network tracing : http://msdn2.microsoft.com/en-us/library/ty48b824.aspx

Interpreting a network trace : http://msdn2.microsoft.com/en-us/library/46fcs6sz.aspx

Posted: Jul 03 2009, 15:37 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Programming
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Adding custom error message to ValidationSummary without validators

Validators are a great thing in the ASP.Net world (as well as the .Net WinForms world...), but sometimes they don't suffice. For example, if you want to validate something not related to a control on the page or something very complex you can't achieve even with the custom validators, you may want a particular solution like this one.

First approach : using the CustomValidator

With this approach you simply have to do the following piece of code when you want to add a custom message to your validator :


CustomValidator val = new CustomValidator();

val.IsValid = false;
val.ErrorMessage = "Custom error message to add to the ValidationSummary";

this.Page.Validators.Add(val);

This is a cool, clean and simple way to add custom error messages to the ValidationSummary.

Second approach : creating a validator by implementing IValidator

The .Net framework allows you to create very custom validator by implementing the IValidator interface. So you create the validator and then use the same technique I've just showed you before, just like this :


public class ValidationError : IValidator
{
    private ValidationError(string message)
    {
        this.ErrorMessage = message;
    }

    public void Validate()
    {
        this.IsValid = false;
    }
}

this.Page.Validators.Add(new ValidationError("Your custom error message"));

Personnaly I prefer this one because you are completely custom and you can add messages in a single line of code.

Posted: Jul 03 2009, 15:15 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Programming
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

I don't see ASP.Net 3.5 on IIS; only 2.0 is there

When you configure IIS, you have to tell it which version of ASP.Net you will be using for the website (or web application). Because you can run multiple versions of the framework on the same server, you have to select the correct version on a dropdown list, just like this :

When you install the framework 3.5 you can be surprised not to see it on the dropdown list.

Why do I don't see the .Net Framework 3.5 on IIS ?

You don't see the 3.5 because it is not a complete framework, it's only an "update" to the 2.0, so you only see 2.0. You will have the same exact behavior for the 3.0 framework as it is also an update to the 2.0 (prior to the 3.5).

If you take a look in C:/Windows/Microsoft.Net/Framework/3.5 you will not see as much stuff as you normally see on the 2.0 folder. For example, if you want to run aspnet_regiis for the .Net framework 3.5 you will not find the tool because the 3.5 is the 2.0 in fact, so you will have to run the aspnet_regiis tool for the 2.0 framework.

What about the 4.0 framework ?

This is a different relaity for the .Net framework 4.0 because it's a complete new framework, not only an update to the 2.0 so in IIS you will see an option in the list for the version 4.0 of the framework.

Posted: Jul 03 2009, 14:36 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

ASP.Net MachineKey generator

When you setup a server involving ASP.Net, you need (if you want to be clean) to set the machineKey. When I do this I always type the same thing on Google : "MachineKey generator". I decided to list some of them I often use :

ASP.Net resources machineKey generator

Pete's Nifty MachineKey generator

OrcsWeb machineKey generator

Posted: Jul 03 2009, 14:26 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Culture ID 2155 (0x086B) is not a supported culture

I recently came across a VERY annoying problem on my personnal (this one) BlogEngine.Net blog.

What happened is that I installed some Windows Updates (a bunch) on my Windows Server 2003 server and then, every time I accessed an article of this blog I received this error message : Culture ID 2155 (0x086B) is not a supported culture. What a real annoying problem !!

I don't know the exact reason but what I know is that cultures are OS specific, so the Windows Update is the cause... it's not related to the .Net Framework so don't waste your time trying to reinstall the framework, it will not work.

The Solution...

Resintall the Service Pack 2 for your Windows Server 2003.

What is a .XAP file (SilverLight) and what does it contain

If you already created a Silverlight application you have certainly noticed that all you do in your Silverlight project will be packaged as a XAP file that you will then put on your website.

What is a XAP file ?

The XAP file is a package that contains everything your Silverlight application needs to run on the client browser.

What does it contain ?

All the assemblies (DLL) you created, all the Framework assemblies you referenced in your application (like System.Xml.Linq, System.Windows.Controls and some others) and a manifest file, named AppManifest.xaml. It also contains culture-specific assemblies (if you translated your application in some other languages).

What does XAP stands for ?

You have to pronounce "ZAP" and it stands for "Silverlight Application Package". I don't know why MS didn't called it SAP instead of XAP but... this is it's meaning !

Can I open a XAP file ?

Oh sure you can, it's only a ZIP file. You can rename it an open it with WinRar or WinZip.

How can I create a XAP file ?

You build your Silverlight project ! Simple, no ?

Why does my Silverlight application is packaged in a XAP file ?

There's 3 main reasons for this :

  1. Because all the content can be compressed within the zip file so you save bandwith and time
  2. Because DLLs are prohibited from downloading (by default)
  3. Because it's easier to download one file than "72" (any number) files
What does the AppManifest.xaml looks like ?

This file is the main entry point in the package for the Silverlight client. When Silverlight extracts the content of the XAP package it reads the AppManifest.xaml to know which assembly it has to load.


<Deployment EntryPointAssembly="SilverlightApplication1">
  <Deployment.Parts>
    <AssemblyPart x:Name="SilverlightApplication1" Source="SilverlightApplication1.dll" />
    <AssemblyPart x:Name="Silverlight.Trace" Source="Silverlight.Trace.dll" />
    <AssemblyPart x:Name="System.Windows.Controls" Source="System.Windows.Controls.dll" />
    <AssemblyPart x:Name="System.Xml.Linq" Source="System.Xml.Linq.dll" />
    <AssemblyPart Source="en/SilverlightApplication1.resources.dll" />
    <AssemblyPart Source="fr/SilverlightApplication1.resources.dll" />
    <AssemblyPart Source="fr/System.Xml.Linq.resources.dll" />
    <AssemblyPart Source="fr/System.Windows.Controls.resources.dll" />
  </Deployment.Parts>
</Deployment>

How do I use a XAP file ?

You ? You don't use this file; Silverlight does. The only thing you have to do with it is copy it to your ASP.Net application.

Where do I deploy my XAP file ?

If you want to do it the common way, deploy it to the ClientBin folder. You can deploy it wherever you want but, I suggest you put it in the ClientBin folder.

Retrieving the entity name or number from a CRM page URL

Recently I had to create an HttpModule that catch every call to a CRM page and inject some JavaScript code in it. The first the HttpModule does is to retrieve to entity name (or number) and instanciates a class that contains some information about the page (organization, page url, entity name, entity number, etc...). Normally it is easy, you can get the etc querystring parameter to get the number and then call the MetaData service to get the entity name. Sometimes the querystring parameter gets another name... it's not always etc: it can be "etc", "oType" or "iObjType".

Life will be too easy if everytime when want to get the entity number we just have to check for the querystring parameter... so Microsoft though about a more challenging way to get the entity number. You will face that if you catch the "areas.aspx" page. This page is the one that is called when you click a left navigation bar item (in an entity record).

Let's check some different URLs you can get in CRM :

For the entity form...

...of CRM entities

 - http://crmserver/org/sfa/accts/edit.aspx (Account)
 - http://crmserver/org/sfa/conts/edit.aspx (Contact)
 - http://crmserver/org/activities/email/edit.aspx (Email activity)

...of user-defined entities

 - http://crmserver/org/userdefined/edit.aspx?etc=#entity_number#

These looks very easy to understand and it's easy to retrieve the entity numer or name. You will have to hard-code the entity number or name in your code when you get CRM entities because the URL (page) tells which entity it is. For the user-defined, you simply get the "etc" parameter in the QueryString.

For the entity record list...

...of the activites, campains and cases

 - http://crmserver/org/workplace/home_activities.aspx
 - http://crmserver/org/ma/home_camps.aspx
 - http://crmserver/org/cs/home_cases.aspx

...of anything else

 - http://crmserver/org/_root/homepage.aspx?etc=#entity_number#

These looks also very easy to understand but you will notice that barely everything (including user-defined entities) are shown in the same page (homepage.aspx) so you will not have to hard-code a lot of thing. And now, for the entity relationship view (the one you get on the right side of the CRM entity form when you click on a left navigation bar item of the entity form)...

...of CRM entities

 - http://crmserver/org/sfa/accts/areas.aspx?oId=[GUID]&oType=1&security=[number]&tabSet=areaContacts (Account showing related contacts)

...of user-defined entities (one-to-many relationship)

 - http://crmserver/org/sfa/accts/areas.aspx?oId=[GUID]&oType=1&security=[number]&tabSet=account_new_myentityname (Account showing related new_myentityname)

...of user-defined entities (many-to-many relationship)

 - http://crmserver/org/sfa/accts/areas.aspx?oId=[GUID]&oType=1&security=[number]&tabSet=areaaccount_new_myentityname (Account showing related new_myentityname)

This not sound very cool... the same querystring parameter (tabSet) can contains 3 different types of value... depending on whether the related entity is custom or built-in and if it is a one-to-many or many-to-many relationship... !

More horrible than this, for the same related entity (shown in different parent entity), the tabSet parameter will not be named the same way (but sometimes it is...). For example, if the related entity is a contact, the tabSet can be named "areaContacts" or "areaSubConts". Wow ! I don't have to tell you it has to be a lot hard-coded !

For the user-defined entities it is a lot more simple than this; the value in the tabSet is the relationship name. This is cool because you can query the CRM MetaData service and get both entities of the relationship. There's only a little twist with this... when you have a many-to-many relationship, the tabSet starts with "area"... I don't know why but MS decided to do it this way so we have to deal with it.

Because the tabSet parameter is a pain, I decided to write an article listing all the different tabSet values I've found in hour of clicking in CRM (because I didn't find it on the web).

Posted: Apr 27 2009, 12:55 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | CRM 4.0 | Programming
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
LINK BUILDING IS PROHIBITED ON THIS WEBSITE