开发者

How to Make Very Simple ASP.Net Password Protected Page

I am looking for a very simple solution to password protect an ASP.Net page.

I found exactly what I am looking for here but it is in ASP and I do not know the syntax to convert it to ASP.Net.

It simply creates a temporary cookie that will expire as soon as they close their browser window.

I am not looking to store the username / password in a db. I will manually change the password occasionally.

Simply helping me convert the following code to ASP.Net would be wonderful!

This goes on the logon.aspx page and pulls values from a 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"开发者_JAVA技巧)<>"") 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

This goes on the password protected page to confirm the cookie was 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


Just use the built-in forms authentication and setup your credentials store in the web.config.

Here's a quick and dirty example

Another example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜