Saturday, February 25, 2012

Route for ASP.NET website and php attacks

When you have a website online, it is common that it is attacked by bots. Most of the time, these attacks aim a php website... And since these robots do not know that my site is in ASP.NET MVC, it suffers for their attacks... As you can see in the next image, my RSS feed (from Elmah (think to visit this site if you are using Elmah : http://asafaweb.com/)) has a lot of errors due to some attacks:


Each attack throws an exception and my logs are unnecessarily cluttered... For this reason, I've had a new route in my Global.asax.cs file:

   1:  routes.MapRoute(
   2:      "PhpAttack",
   3:      "{*allphp}",
   4:      new { controller = "Error", action = "PhpAttack" },
   5:      new { allphp = @".*\.php" }
   6:  );

(note: think to put the page "PhpAttack" in cache)

You can handle these attacks according to your inspiration... For my part, I chose to insert an iframe with a "let me google that for you" link:

   1:  <iframe frameborder="0" src="http://lmgtfy.com/?q=how+to+hack+php" width="100%" height="550px"></iframe>

A little bit more fun than my cluttered RSS feed with useless errors !

Sunday, February 19, 2012

Issue with circular navigation in Windows Phone 7

The good management of the back button is really important: for example, a valid application must quit when you press the back button when you are on its start page. Other constraints must be respected like when you press the back button when a dialog is open (like a ListPicker control), you have to cancel the back behaviour and close the dialog...

For some applications, there's not necessary to think about it because the default behavior is well suited. But for other applications, it will sometimes be necessary to make some changes.

I will show an example of my application (Blind Friends)... If an user wants to play, he will go through these pages:

> >
>

Imagine that the user presses the "back to main menu" at the end of the game, I'll use NavigationService.Navigate(Uri source) to bring him back to home. That will work but if the user presses the back button once he is on the home page, the application will go to the score page because this is the previous page in the navigation stack... My application can be validated with this issue because it must be closed when the user presses the back button on this page.

To regain the normal behaviour, I have modified the URI in NavigationService.Navigate(Uri source):

   1:  NavigationService.Navigate(new Uri("/Pages/MainPage.xaml?homeFromPageScore=true", UriKind.Relative))

And in the codebehind of my home page:

   1:  protected override void OnNavigatedTo(NavigationEventArgs e)
   2:  {
   3:      base.OnNavigatedTo(e);
   4:   
   5:      if (e.NavigationMode == NavigationMode.New && NavigationContext.QueryString.ContainsKey("homeFromPageScore"))
   6:      {
   7:          NavigationService.RemoveBackEntry();
   8:          NavigationService.RemoveBackEntry();
   9:          NavigationService.RemoveBackEntry();
  10:          NavigationService.RemoveBackEntry();
  11:      }
  12:  }

With this workaround, you clean the navigation stack as many times as necessary (neither too much nor too little...). In my case, I'm sure on the number of time I have to remove an element in the navigation stack and the behaviour requested by Microsoft is respected.

Saturday, February 18, 2012

Issue with Chinese (zh) and Windows Phone

(FYI: I'm speaking about the Windows Phone SDK 7.1, these information can change...)

For my first Windows Phone application, I had an issue with the Chinese language... In the ASP.NET MVC version, I use a resource file like this BlindFriendsResource.zh.resx and that works!

So I wanted to keep the same file for the mobile version and... the application was launched in its default language (English).

After some research, I found the solution! I created two files: BlindFriendsResource.zh-CN.resx (Simplified) and BlindFriendsResource.zh-TW (Traditional). These two files correspond to the both supported  languages in Windows Phone.

Using "zh" only will not work for the Chinese language but using "fr" will work for a belgian  person (French speaker: fr-BE) or a french person (fr-FR)... So, finaly, you can see here the list of my resources files:

- BlindFriendsResource.resx
- BlindFriendsResource.es.resx
- BlindFriendsResource.fr.resx
- BlindFriendsResource.nl.resx
- BlindFriendsResource.pt.resx
- BlindFriendsResource.zh-CN.resx
- BlindFriendsResource.zh-TW.resx

I hope that information can be useful for someone ;-)

Tuesday, February 14, 2012

Blind Friends is now on Windows Phone 7

Blind Friends (my Facebook game) is now on Windows Phone 7 market:



I used again the Facebook C# SDK (http://facebooksdk.codeplex.com/) for this mobile application and the ASP.NET MVC version communicates with the WP7 version with some Json...

I will write one or two articles on the development of Blind Friends WP7 (Facebook logout, circular navigation issue, ...)

Découvrez le Nokia Lumia 900 avec MonWindowsPhone