【问题标题】:Request.Form not working when IIS is set to anonymous authentication当 IIS 设置为匿名身份验证时,Request.Form 不起作用
【发布时间】:2009-08-25 15:25:24
【问题描述】:

当 IIS 配置为集成 Windows 身份验证时,我的 asp.net 表单处理程序仅接收表单方法发布数据。当我将其切换到匿名身份验证时, request.form 集合为空。我想为匿名身份验证配置 IIS。这可能是什么原因造成的?我在下面包含了我的代码:

这是我的表单页面 HTML(后面没有代码):


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Testing.aspx.vb" Inherits="Testing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <form name="frm" method="post" action="TestResults.aspx">
    <input type="text" name="mydata" value="" size="25" maxlength="255" />
    <input type="submit" name="submit" value="Submit" />
    </form>
</body>
</html>

这是我的表单处理程序 HTML 代码,后面是列出所有表单变量的代码:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestResults.aspx.vb" Inherits="TestResults" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <div id="resultsid" runat="server">
    </div>
</body>
</html>

Partial Class TestResults
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim aString As String = ""

    For Each item As String In Request.Form
      aString &= item & " = " & Request.Form(item) & "<br />"
    Next

    Me.resultsid.InnerHtml = "<b>The Data:</b><br />" & aString
  End Sub
End Class

【问题讨论】:

  • 您可以使用 Fiddler 或 Firebug 来检查请求中是否确实发送了 POST 数据?只是为了确保它被破坏的是 IIS 而不是浏览器。

标签: asp.net iis


【解决方案1】:

您的表单标签缺少 runat=server。

编辑:仔细观察您正在尝试做的事情,您正在尝试进行跨页面回发。这种类型的回发在 asp.net 中比在旧 asp 中涉及更多。这篇文章可能会有所帮助:

http://www.c-sharpcorner.com/UploadFile/DipalChoksi/xpgpostbk_asp2_dc08102006235543PM/xpgpostbk_asp2_dc.aspx

【讨论】:

  • 我将 runat="server" 添加到表单标签中。那并没有解决问题。不过感谢您的建议。
  • 其实你应该可以把runat="server"从表单中去掉,忽略整个回发机制,直接在Request.Form里随便看看。不一定是个好主意,当然也不是非常“.NET-y”,但它应该仍然有效。
  • 我倾向于放弃我的跨页回发策略,看看我是否可以获取 Request.Form 的内容。
  • 将我的代码更改为仅向自身提交数据(无跨页回发)。它在 IIS 设置为集成 Windows 身份验证时工作。当 IIS 设置为匿名身份验证时,它不起作用。当它工作时,我可以从 Request.Form("mydata") 集合中获取我的数据。
  • 重新编写了我的代码以尝试跨页回发。它仅在 IIS 设置为集成身份验证时才有效。当 IIS 设置为匿名身份验证时,它将不起作用。我认为这不再是代码问题。我认为这是一个 IIS 问题
猜你喜欢
  • 2020-12-15
  • 2019-01-09
  • 2020-12-21
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多