以下代码段不起作用,有人可以帮我识别问题。我在IIS 7.0上使用ASP
代码:
<%If session("var") <> "" Then
If( instr(strSQL("Platform"), session("osversion")) > 0 ) Then %>
<input type="image" src="images/download2.gif" name="submit" value="submit" />
<%Else %>
<p style="font-weight:bold"> SOME ERROR MESSAGE</p>
<%End If %>
<%Else %>
<input type="image" src="images/download2.gif" name="submit" value="submit" />
<%End If %>
问题是否与经典ASP的IIS 7.0配置有关?
答案 0 :(得分:0)
尝试删除嵌套()
中的“If
”。像下面的代码:
<%If session("var") <> "" Then
If instr(strSQL("Platform"), session("osversion")) > 0 Then %>
<input type="image" src="images/download2.gif" name="submit" value="submit" />
<%Else %>
<p style="font-weight:bold"> SOME ERROR MESSAGE</p>
<%End If %>
<%Else %>
<input type="image" src="images/download2.gif" name="submit" value="submit" />
<%End If %>
现在,在第一个if条件If session("var") <> "" Then
中发生的事情,由于<%Else %>
,应始终存在输出。该问题将被修改为nested if
。检查strSQL("Platform")
和session("osversion")
的值。如果这两个都没问题,请立即检查instr(,)
。您甚至可以If instr(strSQL("Platform"), session("osversion")) > 0 Then
更改为If true Then
,只是为了检查它是否有效。
答案 1 :(得分:0)
代码......
您的代码:
if a
if b
do alfa
else
do bravo
else
do alfa
重写:
if not a or b
do alfa
else
do bravo
现在在ASP
<%
dim showButton, errMsg
showButton = "<input type='image' src='images/download2.gif' name='submit' value='submit' />"
errMsg = "<p style='font-weight:bold'> SOME ERROR MESSAGE</p>"
If session("var") <> "" Then
If( instr(strSQL("Platform"), session("osversion")) > 0 ) Then
response.write showButton
Else
response.write errMsg
End If
Else
response.write showButton
End If
%>
<%
dim showButton, errMsg
showButton = "<input type='image' src='images/download2.gif' name='submit' value='submit' />"
errMsg = "<p style='font-weight:bold'> SOME ERROR MESSAGE</p>"
If session("var") = "" or (instr(strSQL("Platform"), session("osversion")) > 0) Then
response.write showButton
Else
response.write errMsg
End If
%>
<%
If session("var") = "" or (instr(strSQL("Platform"), session("osversion")) > 0) Then
response.write "<input type='image' src='images/download2.gif' name='submit' value='submit' />"
Else
response.write "<p style='font-weight:bold'> SOME ERROR MESSAGE</p>"
End If
%>