Here I have requested the email, timezone and nickname. I could also say Require for these if I absolutely must have them. You should also provide a privacy policy URL, or else the user will be warned that it is missing.

The control itself provides a Register link that is customizable, allowing users to sign up with an Open ID provider such as www.myopenid.com.

When you login, if you have entered a valid OpenID URL, you will go to your OpenID provider who will ask for your password if necessary, confirm whether you want to allow that site to log you in once, always or never, and ask you what persona you want to use.

On a successful login, you can retrieve the OpenID URL as well as anything from the persona that has been made available. Here's some sample code-behind.

As you can see, it is pretty simple. I still need to work out how I am then going to integrate the OpenID login with my own site login database. The control itself also has a few limitations. In particular, entering an invalid URL causes an unhandled exception. It also doesn't give you an event for login failure (although there is a "logging in" event which I am not sure what it is for).

Comments

July 11. 2007 06:39

Thanks for your explanatory post. I'm sorry my instructions weren't that good, but I see you've made up for that.

The LoggingIn event gives your site a chance to reject a particular URL before the user is redirected to his OpenID provider. You might do this if you only allowed, say, a given set of administrators with known OpenIDs to log into your site.

The unhandled exception isn't good. There should be a validation control to handle that, but I'll have to check.

In the meantime, you and your readers should know that the NerdBank.Tools version of my ASP.NET OpenID control is now deprecated. The controls were merged into the dotnetopenid project (http://code.google.com/p/dotnetopenid) and have been worked on there. You should give that library a try and see if you find it better. I welcome comments. Just post to the dotnetopenid Google Group (http://groups.google.com/group/dotnetopenid).

Thanks for ur reply!I have found dll.But now I have another problem.where can I download source code?Because I can't change the OpenID control.For example,I want to change the OpenID provider from myopenid to yahoo.

aaballboy,The source code is also available from the googlecode site that Mark pointed out. But FWIW, you don't need the source to change the OpenId Provider that is suggested in the OpenIdLogin control. You can change that through a property on the control itself. Much easier.

Thanks your code works great. But now I am trying to break it down indivigual users and allow only certain users in. For example, what would I set my xxx to in allow users="xxx" in the web.config file?

Rather than using your web.config file to list the individual users allowed to log in, if the purpose is to whitelist who is allowed to log in at all then inside your openIdLogin_LoggedIn handler you should check e.ClaimedIdentifier and if it isn't on your whitelist, set e.Cancel = true, and display a message to the user saying that they're not allowed to log in.

About Mark Heath

I'm a Microsoft MVP and software developer based in Southampton, England, currently working as a Software Architect for NICE Systems. I create courses for Pluralsight and am the author of several open source libraries. I currently specialize in architecting Azure based systems and audio programming. You can find me on: