3
Reply

securing web forms using forms authentication

Pradip Kishore

Pradip Kishore

Jan 31 2007 12:58 AM
2.4k

i have two web pages(login.aspx and account.aspx)i want to secure my account.aspx from unauthorised access.i used forms authentication as modified the web.config as follows:
<configuration>
<authentication mode="Forms">
<forms name="AuthCookie" loginUrl="/login.aspx" />
</authentication>
</configuration>

in the login button  click event the codes are as follows:
if username.text="pradip" and password.text="pkc" then
FormsAuthentication.RedirectFromLoginPage(username.text,false)
else
labelmsg.text="invalid user name or password"

now my problem is that when ever i am directly accesing accout.aspx(without logging in),it is not automatically redirecting to login.aspx..

suoopse i have 10 webforms in my project out of which i want to make 5 web forms secure so that if any  unauthorised user wants to access them,they will be automatically redirected to login.aspx ..how can i do this(i think that i have to check the cookie value "AuthCookie" in the page load event of the secure pages..but i dont know how to do it..

if i write request.cookies("AuthCookie").value is nothing then response.redirect("login.aspx").. in the page load events of the secure pages then also it is not redirecting to login.aspx..plz help me out this..its urgent ..

thanks in advance


Answers (3)