Tuesday, July 31, 2012

Solve "ASP.NET 4.0 has not been registered on the Web server" issue

If you are working on IIS web server and you get an error saying that ASP.NET 4.0 has not been registered on the Web Server (see following screenshot)


A simple way to solve above issue is to run aspnet_regiis.exe. Simply open command shell in administrator mode and execute following command

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

Tuesday, July 17, 2012

Using Single Sign-on (windows live) in Windows 8 Metro App

I was playing around with Windows 8 Metro api (will try to post a blog post covering basics of that later) and I thought of using SSO (Single sign on) using Windows live account for membership. This was an obvious option considering Windows 8 allows you to use your windows live account to sign in to windows 8. And moreover, most of the Windows 8 metro applications do use SSO for membership. During the implementation, I hit a roadbump and it took a lot of time to fix the problem, since, the issue wasn't mentioned on any of official blog posts (though answer to some questions on public forums did help out) so I thought to write a simple step by step procedure to cover this. I am covering C# api but the concepts apply on both Javascript and C++ apis as well. (keep in mind this tutorial is specific for Windows 8 Metro api which is available in Visual Studio 2012)

1. First of all, download and install Windows Live SDK (http://go.microsoft.com/fwlink/p/?LinkId=224535)

2. Create a Blank application under Metro style application (found under C# template)

3. In Solution explorer, right click on "References" node under your project and click "Add Reference"

4. Click Windows -> Extensions -> Live SDK and click OK

5. Open MainPage.xaml.cs (or the page on which you want to add controller), add following references to Windows live libraries;

using Microsoft.Live;
using Microsoft.Live.Controls;

and declare following as global private variables

private LiveConnectClient client;
private LiveConnectSession session;


6. Now, open MainPage.xaml file and in the "Page" tag, add following namespace for windows live sdk;

xmlns:live="using:Microsoft.Live.Controls"

7. Add following windows live sign-in button under the Grid you want to host sign-in button controler

<live:SignInButton x:Name="btnSignin" Scopes="wl.signin wl.basic" SessionChanged="btnSignin_SessionChanged" />
<TextBlock Height="32" Foreground="White" Name="infoTextBlock" Width="419" />

As soon as the session/state is changed, a function btnSingin_SessionChanged will be called. (the second tag is just to show the sign in status)

8. Now, let's add a simple code in session changed handler:

private async void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
        {
            if (e.Status == LiveConnectSessionStatus.Connected)
            {
                session = e.Session;
                client = new LiveConnectClient(session);
                LiveOperationResult operationResult = await client.GetAsync("me");
                try
                {
                    dynamic meResult = operationResult.Result;
                    if (meResult.first_name != null &&
                        meResult.last_name != null)
                    {
                        infoTextBlock.Text = "Hello " +
                            meResult.first_name + " " +
                            meResult.last_name + "!";
                    }
                    else
                    {
                        infoTextBlock.Text = "Hello, signed-in user!";
                    }
                }
                catch (LiveConnectException exception)
                {
                    this.infoTextBlock.Text = "Error calling API: " +
                        exception.Message;
                }
            }
            else
            {
                infoTextBlock.Text = "Not signed in.";
                client = null;
            }
        }

9. At this point, if you try to try Single sign-on, you'll see the windows live sign in dialog, but when you try to login, it'll keep giving you error that "An error occurred while performing the operation. Please try again later" and if you see the stack trace it points to mscorlib. In order to make sure that this works, goto https://manage.dev.live.com/build and follow instructions mentioned there.Once, you complete 2 step procedure mentioned at above url, SSO will start working.

hope this helps.
 
Reference: http://msdn.microsoft.com/en-us/library/live/hh826551.aspx