Nikolaos Kantzelis ASP.Net Blog

This blog will focus on ASP.NET Framework

Sponsors

About Me

Great Blogs

Membership in ASP.Net applications - part 2

This is the second post in a series of posts regarding ASP.Net built in membership functionality,providers,controls. You can read the first one post one here .

In order to follow this post, complete the steps in the first post. It will only take 10 minutes or so.

1) Launch Visual Studio 2005,2008/2010. Express editions will work fine. I am using Visual Studio 2010 Ultimate edition.


2) Follow all the steps in the first post of the series.

3) Run your application to make sure it runs.

4) Change the web.config file by commenting out these lines of code.

<!--<authorization>

<deny users="?"/>

</authorization>
-->

 

5) In the Default.aspx page I am going to make some changes. I am going to use the LoginView control and the LoginStatus control.There are 2 templates,AnonymousTemplate and LoggedInTemplate. I place a LoginStatus control in the AnonymousTemplate.I place a LoginStatus control and the same LoginName control I had before in the  LoggedInTemplate.

<asp:LoginView runat="server">

<AnonymousTemplate>

you are not logged in .

<br />

<asp:LoginStatus ID="LoginStatus1" runat="server" />

</AnonymousTemplate>

<LoggedInTemplate>

You are logged in, <asp:LoginName ID="LoginName1" runat="server" /><br />

<asp:LoginStatus ID="LoginStatus1" runat="server" />

</LoggedInTemplate>

</asp:LoginView>

 

6) Run your application and the first time you try to access the default.aspx page you will see a link prompting you to log in. When you click on it you will be redirected to Login.aspx page where you can log in and if you are logged in successfully you will see your username and a link labelled "Logout".

7) Let's add another item in our site, a web form.We will call it RecoverPassword.aspx. We want to provide a way for a user to recover the password in case he has forgotten it. Drag and drop a PasswordRecovery control on the form.

There are 3 Views in this control, Username,Question,Success. You can fully configure this control and add you own text. In order for this control work you need to configure the smtp settings. You can do that from that the WAT tool.

8) In the Login.aspx page we must add a link to RecoverPassword.aspx page.the We can do that by setting the property PasswordRecoveryText to forgot password? and PasswordRecoveryUrl to RecoverPassword.aspx

9) Run your application again. Click on the link above that takes you to the RecoverPassword.aspx page.Follow the steps of the wizzard. You will get an error in the last step but this is due to the lack of configuration of the smtp settings.

10) Now we need a way to let the user sign up to the site. Up to this point we created users from our WAT tool. Add another item to your site, a web form. Name it Register.aspx.

Drag and drop a CreateUserWizard control on the form.You can configure this control from the properties. There are so many options in this control to set texts and styles.

Set the ContinueDestinationPageUrl to Login.aspx page.

11) In the Login.aspx page we must add a link to Register.aspx page.the We can do that by setting the property CreateUserText to Register and CreateUserUrl to Register.aspx

Run your application and register with the site by creating a new user.

12) We will modify the default.aspx page so we can add the functionality of changing the password when the user logs in.

We will do that by adding a ChangePassword control to the LoggenInTemplate of the LoginView control.In my case the markup looks like that

<asp:LoginView runat="server">

<AnonymousTemplate>

you are not logged in .

<br />

<asp:LoginStatus ID="LoginStatus1" runat="server" />

</AnonymousTemplate>

<LoggedInTemplate>

You are logged in, <asp:LoginName ID="LoginName1" runat="server" /><br />

<asp:LoginStatus ID="LoginStatus1" runat="server" />

<br />

<asp:ChangePassword ID="ChangePassword1" runat="server">

</asp:ChangePassword>

</LoggedInTemplate>

</asp:LoginView>

13) Run your application, log in, change the password and logout. Log in again with the new password.

So what have we achieved so far?We managed to create a membership based portal without writing any code.Stay tuned for more posts on the isue

Hope it helps!!!

Comments

No Comments