I am looking for a very simple solution to password protect ASP.Net pages.
I found exactly what I am looking for here , but it is in ASP, and I donβt know the syntax to convert it to ASP.Net,
It simply creates a temporary cookie that expires as soon as they close their browser window.
I do not want to store username / password in db. Sometimes I will change the password manually.
Just helping me convert the following code to ASP.Net would be great!
This happens on the logon.aspx page and pulls values ββfrom the form.
Username="Administrator"
Password="Admin"
Validated = "OK"
if Strcomp(Request.Form("User"),Username,1)=0 AND Request.Form("password") = Password then
Response.Cookies("ValidUser") = Validated
If (Request.QueryString("from")<>"") then
Response.Redirect Request.QueryString("from")
else
Response.Redirect "MyPage.aspx"
End if
Else
If Request.Form("User") <> "" then
Response.Write "<h3>Authorization Failed.</h3>" & "<br>" & _ "Please try again.<br> <br>"
End if
End if
This page is password protected to confirm that a cookie has been created.
Validated = "OK"
if Request.Cookies("ValidUser") <> Validated then
dim s
s = "http://"
s = s & Request.ServerVariables("HTTP_HOST")
s = s & Request.ServerVariables("URL")
if Request.QueryString.Count > 0 THEN
s = s & "?" & Request.QueryString
end if
Response.Redirect "Logon.aspx"
End if