Tuesday, March 18, 2008

Encoding mailto in hyperlink against spam bots

Scanning pages for hyper link with mail
On almost each html tutorial you can find how to create link, which openes user's default mail application.

Don't do that
- after creating such page, your mailbox will contain almost only spam e-mails.

Solution 1 - creating dummy human readable address
You can paste on your page:

Yes - it's working, but do you really want place it on your company site. Imagine link on home page: "Contact our consultant - send sales_at_professional_REMOVE_IT_company.com" - actually it does not seems to be very professional.

Solution 2 - encode with javascript
Concept: Instead of creating

Create on output page with javascript encoded email - spam-bots does not parse javascript, so email will not be properly generated:

In browsers supporting javascirpt it will be displayed as earlier, because document.write is processed immediately after loading:

  1. Import javascript decode64 function

  2. Create ASP.NET filter which finds all occurences of hyperlinks with mailto:

  3. Replace all occurrences with javascript which produces document.write in javascript

  4. Add configuration in web.config

Monday, March 17, 2008

Publishing Web Application with MsBuild

Visual Studio 2005 has features that can used to publish a website in a production server or a staging server.When you compile files using the Publish Web Site utility the source code is removed. The marked up code in the .aspx files can also be removed optionally. After compilation the .aspx pages point to the compiled versions. With this feature the source code of your pages are safe. Accessing your code by others is difficult. This is one of the features that are more useful for those who want their code to be safe.

Question is how to automate it?

1. Add target to .csproj file
Ensure your web application project contains :

2. Call hidden task _CopyWebApplication
Call task from msbuild:

3. Resolve references to other projects
Unfortunatelly task _CopyWebApplicaiton does not copy output from referenced project so you have to do it manually by calling ResolveReferences task

Update: Publishing Websites with cascade dependency (2009.02.03)

It's quite common that you have project structure like on image below. Web site on top of Business Logic Layer, which is on top of Data Access Layer.

Unfortunately, solution posted above does not solve second degree references (references of references) and therefore. When project is built with code above only first degree are propery copied to output directory.

In order to configure all degree references to be copied you have to specify both
  • WebProjectOutputDir - where website will be published
  • OutDir - where all assemblies should be placed (bin folder>

In MsBuild script you can use snippet as below:

<MSBuild Projects="WebApplication\WebApplication.csproj"

Properties="Configuration=Release;WebProjectOutputDir=..\build\Release\Web\;OutDir= ..\builda\Release\Web\bin\"

Targets="ResolveReferences;_CopyWebApplication" />

Thanks to Maciej Grzyb for solution http://maciek79.secondbrain.com