Print Page | Close Window

Password Protecting ASP.net Page

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=11447
Printed Date: 28 March 2026 at 11:06pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Password Protecting ASP.net Page
Posted By: Misty
Subject: Password Protecting ASP.net Page
Date Posted: 05 August 2004 at 9:58pm

Can someone tell me the code that I should use to password protect an ASP.Net page?

I have an ASP.net page for password protection that is named login.aspx.

In ASP, you would do something like:

if Session("UserName") = "" then
Session("Message") = "You must log in before viewing that page!" response.redirect "Login.asp"
end if




Replies:
Posted By: Diep-Vriezer
Date Posted: 06 August 2004 at 7:41am
Hm, well, you could use the ASP.NET Forms security system. I don't have much time now, so you should read about it in your MSDN library, or google for it.

-------------
Gone..


Posted By: michael
Date Posted: 06 August 2004 at 9:08am
I agree with Diep use Forms authetication, that way you don't have to put any extra code on pages, you juse define your login.aspx site and set the requirements in your web.config. 4guysfromrolla has an excellent article on that.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: scottage
Date Posted: 20 August 2004 at 6:05am

If you want the equivalent code in .net as classic asp try

if (Session["username"] == null || Convert.ToString(Session["username"]) == "")
{
Session["message"] = "You must log in before viewing this page";
Response.Redirect("Login.aspx");
}

Visit http://www.realwebdevelopers.com - http://www.realwebdevelopers.com  for help with asp and asp.net




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net