我正在寻找一个非常简单的解决方案来密码保护 ASP.Net 页面。
我找到了我正在寻找的东西here但它是在 ASP 中,我不知道将其转换为 ASP.Net 的语法。
它只是创建一个临时 cookie,一旦用户关闭浏览器窗口,该 cookie 就会过期。
我不想将用户名/密码存储在数据库中。我偶尔会手动更改密码。
只要帮助我将以下代码转换为 ASP.Net 就太好了!
这出现在 logon.aspx 页面上并从表单中提取值。
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
这会出现在受密码保护的页面上,以确认 cookie 已创建。
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
最佳答案
关于asp.net - 如何制作非常简单的 ASP.Net 密码保护页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4619579/