0

在一个我刚刚被要求修改的旧网站上,我添加了一些 VBScript(不熟悉它,只是试图伪造它直到我成功),如下所示:

'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()

ReturnMsg = "Made it to IsNewBusiness logic"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)

在我添加“End If”行之前,它失败了 - 导航到该页面给了我一个错误消息。

添加“End If”后,错误消息消失了,但没有显示 javascript 警报(只是暂时让我知道代码确实运行了),为什么不显示?

使用 F12(我必须在 IE11 中以兼容模式运行它),我查找了这个文件,以便我可以在其中放置一个断点,但它似乎并没有使自己可用。

更新

根据 Archer 的回答,我用以下代码替换了我的代码:

ReturnMsg = "IsNewBusiness logic not reached"
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
    ReturnMsg = "Made it to IsNewBusiness logic"
End If
adoRS.Close()

%> <!-- this indicates the end of aspx - start of markup -->

<script type="text/javascript">
    alert("<%= ReturnMsg %>");
</script>

<% 

...但是当我导航到该页面时,我仍然没有看到任何警报。

4

1 回答 1

1

好吧,第一件事。您不需要Response.Write()在 aspx 文件中使用,因为这是在执行后将作为标记发送到浏览器的内容。您可以在其中放置任何类型的普通标记,包括 Javascript。因此,您可以将当前拥有的内容更改为...

'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()

ReturnMsg = "Made it to IsNewBusiness logic"

%> <!-- this indicates the end of aspx - start of markup -->

<script type="text/javascript">
    alert("<%= ReturnMsg %>");
</script>

<% <!-- this indicates end of markup but is only required if you have any further aspx code -->
于 2017-03-02T09:33:08.823 回答