gpt4 book ai didi

asp.net - 如何制作非常简单的 ASP.Net 密码保护页面

转载 作者:行者123 更新时间:2023-12-02 10:25:02 26 4
gpt4 key购买 nike

我正在寻找一个非常简单的解决方案来密码保护 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>&#xa0;<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

最佳答案

只需使用内置表单例份验证并在 web.config 中设置您的凭据存储。

Here's a quick and dirty example

Another example

关于asp.net - 如何制作非常简单的 ASP.Net 密码保护页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4619579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com