Tuesday, April 3, 2012

Facebook C# SDK and logout on Windows Phone

(Facebook C# SDK version: 5.4.1.0)

Most tutorials explain how to connect to Facebook for a Windows Phone application... But the logout is rarely mentioned while it is a very important feature for the users of your application.

So, how can you propose the possibility of logout to your users? We suppose that you already have a WebBrowser used for the login: we will call it "FacebookWebBrowser".

To make a logout from this WebBrowser, you just have to do that:

   1:  FacebookWebBrowser.Navigate(new Uri(String.Format("https://www.facebook.com/logout.php?next={0}&access_token={1}", _loginUrl, _accessToken)));

The _loginUrl comes from the "GetLoginUrl" method (from the Facebook C# SDK) and the _accessToken comes from a previous login on Facebook.

Nothing complicated but very useful to know!

Saturday, March 10, 2012

SPUpgradeException was thrown

I was trying to install SharePoint Server 2010 on my laptop which runs Windows 7 x64 and the configuration failed at the second step:
Exception: Microsoft.SharePoint.Upgrade.SPUpgradeException: Failed to call GetTypes on assembly Microsoft.Office.Server.Search
The error does not help you a lot... But the problem occurs if your Windows 7 does not have the Chart Control installed.

You just have to quit the configuration wizard and to download the Chart Control here. You can now restart your configuration wizard, this should work better now!

Monday, March 5, 2012

Could not load file or assembly 'msshrtmi' or one of its dependencies

Today, for no reason, one of mine projects in ASP.NET MVC 3 crashed at launch... I had this error every time:


After some searches, I've found the solution:

  • unload your web project
  • edit the .csproj file
  • remove all "PlatformTarget" elements that you found
  • reload your web project

Normally, it should be enough but I have also changed my build configuration to x64 (inspite of Any CPU).

Hope that information can be useful for someone!

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.