Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Password Protecting ASP.net Page
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Password Protecting ASP.net Page

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Password Protecting ASP.net Page
    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

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post 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..
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
scottage View Drop Down
Newbie
Newbie


Joined: 20 August 2004
Location: United Kingdom
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote scottage Quote  Post ReplyReply Direct Link To This Post 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 for help with asp and asp.net

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.