Restricting access to member area in ASP

We can create a member only area in asp by using sessions. Userid of the member is stored in session variable and presence of this session variable is checked at the beginning of each page inside the member area. If session with userid is available then further script execution is allowed, otherwise the script execution is stopped and a message asking the member to login is displayed.

The session for every member is created at login page where a session with userid of the member is created after successful login of the member.

This member area pages links we can display once a member is successfully logged in but members may bookmark the URL of member area and may try to access the member area pages without logging in so session checking is a must for all these restricted pages.

We have to keep this checking if session status at the top of each page, here a better idea is to keep all these code inside one file and include that file at the staring of each page of member area. Like this ..

Now inside this check.asp file we will keep the code to check the user session status. Here it is .

if (IsEmpty(Session("userid"))) then

Response.Write "Member area. Please <a href=''../login.asp''>login</a> to use this page "

End if

You can see in the above code if the Session(“userid”) is not available then IsEmpty function will return true and the code inside the if condition will be executed. The fist line will display the message with a link to login page and the next line Rsponse.End will stop further execution of the page.

This is a simple way to restrict access inside member only page for logged in users only.

Be the first to post comment on this article :

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer