Tags: , , | Categories: asp.net mvc, development Posted by pieterg on 5/24/2010 8:06 PM | Comments (0)

For those who have not yet seen Stackoverflow or Twitter’s Notification Panels. You are missing out.
image

It’s a neat way to display messages to your users without being too intrusive.

There has been quite a lot of noise regarding ASP.NET MVC with the release of version 2.0. Not to mention the amount of noise the JQuery community has been making. This usually follows by the line, “JQuery is the best thing since sliced bread :)”

Since ASP.NET MVC is not a replacement for ASP.NET Webforms, let’s explore how we can incorporate a notification bar in ASP.NET Webforms.

You can use the following method with any JQuery type notification panel/bar but for this sample grab the Notify Bar from Dmitri Smirnov.

1. Include the jquery.notifyBar.css and jquery.notifyBar.js in your master page
2. Add a static class to your project e.g. (Note the use of extension methods here)

/// <summary>
/// Notification Helper
/// </summary>
public static class NotificationHelper
{
	/// <summary>
	/// Show Message
	/// </summary>
	/// <param name="message"></param>
	public static void ShowNotification(this System.Web.UI.Page page, string message)
	{
		page.ClientScript.RegisterStartupScript(typeof(Page),
												"notificationScript",
												"<script>$(function () {$.notifyBar({html: '"+message+@"',delay: 2000,animationSpeed: 'normal'});});</script>");
	}
}

Now in your Pages you could just call the

Page.ShowNotification(“Hello World!”);
Tags: , | Categories: asp.net mvc, rpx Posted by pieterg on 5/23/2010 4:26 AM | Comments (2)

The most annoying part of getting to a site is the bit where you have to register. It’s annoying having to complete a 50 page essay just to become part of the community. Since now, there have been numerous attempts to provide a single sign on facility and the only one worth exploring for me was RPX Now.

Let’s take a look at Stackoverflow and how Jeff Atwood and his team have just nailed the registration process.

image

Clicking on the Log In button will take you to a page that will ask you which provider you wish to sign in with. In my case, let’s use MyOpenID.

image

This will take you to myopenid.com and ask you to verify yourself and WHAM! You can associate your id with Stackoverflow and registration is complete. How did Jeff and his team manage this? I don’t know but it’s magic!

The one way to implement this is to use RPXNow and grab the RPXLib.

First up is to understand the process of RPX and how it will interact with your site. To break it down into simple bits.

1. User clicks on your log in link.
2. User is asked to choose a provider, be it twitter, google or openid.
3. User enters their credentials and gets passed into a void
4. Moments later the user is passed back to your page with a token. You can utilize this token to get details about the user.

1. User Clicks on your log in link

After following the simple directions on RPX Now, you should have a bunch of javascript and a link that was given to you.

<script type="text/javascript">
	var rpxJsHost = (("https:" == document.location.protocol) ? "https://" : "http://static.");
	document.write(unescape("%3Cscript src='" + rpxJsHost +
"rpxnow.com/js/lib/rpx.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	RPXNOW.overlay = true;
	RPXNOW.language_preference = 'en';
</script>

<a class="rpxnow" onclick="return false;" href="https://mvcwebshop.rpxnow.com/openid/v2/signin?token_url=''>Sign In</a>

4. Moments later the user is passed back to your page with a token. You can utilize this token to get details about the user.

The user is passed back to your control and you are given a token to query the rpx service with.

/// <summary>
/// Sign In
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost]
public ActionResult SignIn(string token)
{
	return View();
}

Remember, to include the token as part of the parameters of the Action. Also, note the use of the attribute HttpPost. This tells asp.net mvc that this action will only respond to Http Posts.

Using this token and RPXLib, we can very easily query the service to get the user details, like so :)

/// <summary>
/// Sign in the user 
/// </summary>
/// <param name="username"></param>
/// <returns></returns>
public bool SignIn(string token)
{
	RPXLib.RPXService service = new RPXLib.RPXService(new RPXLib.RPXApiSettings("http://rpxnow.com/api/v2/auth_info", "youruniqueAPIKey"));
	try
	{
		RPXLib.Data.RPXAuthenticationDetails userDetails = service.GetUserData(token);
		return true;
	}
	catch (RPXLib.Exceptions.RPXAuthenticationErrorException ex)
	{
	}
	return false;
}

Remember that when setting up RPXNow, you can point it to your local development server (http://localhost:1234/SignIn/).

Have fun with it