【问题标题】:X10Hosting Password Protect PagesX10Hosting 密码保护页面
【发布时间】:2014-10-15 16:43:29
【问题描述】:

已解决

我的问题是如何我可以用密码保护不是文件夹,但也可以保护文件(页面)。它只允许我对文件夹进行密码保护,并且我希望能够像 php 一样使用它来重定向到登录页面,如果你去它并且我设置的当前密码/用户名是正确的,那么它将再次将您返回重定向到最初受保护的页面,或者仅使用我不知道的简单功能将其重定向到登录页面。

我已经尝试过的事情

  • x10Hosting 提供的重定向功能
    • 无法使用,因为返回它会自动将其重定向回登录页面;导致无限循环。
  • 将它放在一个文件夹中并从那里访问它
    • 我有一个秘密页面,其中包含即将发生的事件和项目、隐藏页面等,供老师和同学使用。密码保护文件夹只能通过查看索引来访问它,他们都没有能力或智能来弄清楚如何操作。另外,我必须创建一个单独的 FTP 帐户,他们也不知道如何操作。

注意事项

  • 我曾经有一个系统,它使用 .aspx 扩展页面并且在 login.aspx 页面和 secret.aspx 页面本身的 <html> 之前有一个 <? ?>(我假设是 PHP)打开/关闭标签,但现在从我的旧网络主机迁移到 x10Hosting,它将 .aspx 文件作为文本文档读取,导致它在加载时打开为文本文档,所以我不能使用我认为的 .aspx 扩展名 /em> (是唯一的)不支持<? 标签,导致它只显示为页面上方的文本。我已经丢失了那个代码。
  • 我希望它能够在单独的页面上有一个简单的登录表单,而直接进入机密页面会将其重定向到 login.? 页面,您输入我设置的密码和用户名,如果正确,我会假设单击按钮(<input type="submit">)会自动将您重定向到秘密页面。

【问题讨论】:

  • 旁注:AddHandler application/x-httpd-php .aspx 中的 .htaccess 应该允许在 .aspx 文件中执行 PHP。但是,我不知道 X10 的限制。
  • 谢谢,但这不是允许 PHP 执行的事实;事实上,它甚至没有作为 html 加载,而是作为“text/x-generic”文件类型加载,只加载代码本身,@Ohgodwhy
  • 那是因为没有解释器来解析创建的 .aspx 扩展并且 apache 默认不会尝试解析它,因此它通过默认设置应用x-generic。试试我的建议?
  • 当然;得到结果后,我会立即编辑此评论。 #EDIT 工作正常,谢谢!

标签: javascript php asp.net redirect


【解决方案1】:

已解决;想通了

在@Ohgodwhy 的帮助下,我设法恢复了我的旧系统。使用 PhP,我为我的秘密页面使用了以下代码;

<%
Validated = "OK"
if Request.Cookies("ValidUser") <> Validated then
'Construct the URL for the current page.
    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
    'Redirect unauthorized users to the logon page.
    Response.Redirect "Logon.asp?from=" &Server.URLEncode(s)
End if
%>
<html>
...
</html>

然后我在登录页面使用了以下代码;

<%
Username="[insert]"
Password="[insert]"
Validated = "OK"
if Strcomp(Request.Form("User"),Username,1)=0 AND Request.Form("password") = Password then
'Set the validation cookie and redirect the user to the original page.
    Response.Cookies("ValidUser") = Validated
    'Check where the users are coming from within the application.
    If (Request.QueryString("from")<>"") then
    Response.Redirect Request.QueryString("from")
    else
    'If the first page that the user accessed is the Logon page,
        'direct them to the default page.
          Response.Redirect "secret.aspx"
    End if    
Else
' Only present the failure message if the user typed in something.
    If Request.Form("User") <> "" then
        Response.Write "<h3>Authorization Failed.</h3>" & "<br>" & _
        "Please try again.<br>&#xa0;<br>"
    End if
End if
%>
...
<div id="body">
<form action=<%Response.Write "LogonSecurity.asp?"&Request.QueryString%> method="post">
<h3>Login</h3>
<p> 
Username: 
<input type="text" name="User" placeholder="Username" value='' size="20"></input>
Password: 
<input type="password" name="password" placeholder="Password" value='' size="20"></input>
<input type="submit" value="Logon"></input>
</form>
</div>
...
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 2011-06-21
    • 2017-02-03
    • 1970-01-01
    • 2021-02-10
    • 2011-07-31
    • 1970-01-01
    相关资源
    最近更新 更多