javascript - 本地主机无法连接到 IIS 中的 ASP 文件
问题描述
[编辑:找到解决方案。我只是没有设置或尝试正确访问本地主机,这意味着文件没有被加载。一旦我尝试通过 localhost 而不是绝对路径访问文件,我发现它们有效。我会留下这个问题,以防它在未来对某人有所帮助。]
我正在尝试在 9 月份开始上课之前完成一个网络表格练习。目标很简单:制作一个接受一些用户输入的 HTML 文件,并将其发送到本地托管的 ASP 文件(不是 ASP.NET),以确认数据已实际发送。不需要解析数据,只需识别它是使用 GET 或 POST 成功发送的。
我已经制作了 HTML 文件,并且作为练习的一部分提供了 ASP 文件。我已经彻底检查了它们,并且元素正在正确发送数据,但 ASP 文件似乎没有正确接收它。
我已完成以下步骤,在运行 Windows 10 的笔记本电脑上使用 IIS 配置 ASP 文件:
安装 IIS 并支持经典 ASP 文件
确保默认端口 (80) 已打开并正在侦听
确保网站在 IIS 中运行
但是,当我尝试使用 localhost/fileName.asp 作为 URL 浏览网站时,它无法正确加载。相反,我收到错误“localhost 拒绝连接”。当我尝试使用 IIS 管理器界面中的“浏览”按钮浏览该站点时,我收到错误消息“找不到本地主机应用程序”。
奇怪的是,当我在浏览器中打开 HTML 页面并单击提交按钮时,它会将我重定向到 .ASP 页面,但不会执行其中的任何内容。它只显示文件的文本内容。
作为参考,我在下面提供了我的 HTML 页面和 ASP 页面的代码。我已经从 HTML 页面中删除了输入元素,因为它们与我的问题无关。
HTML:
<html>
<head>
<title>SET Registration</title>
</head>
<body>
<div name="errorMessage" id="D3" style="color:red"></div>
<form action="C:\inetpub\wwwroot\testRequest.asp" method="get">
<!--INPUT ELEMENTS THAT GET INFORMATION FROM USER-->
<!--BUTTONS THAT CLEAR/VALIDATE/SUBMIT FORM INFORMATION-->
<input type="button" name="cancelForm" id="B1" value="Clear all" onclick=clearAll()>
<input type="button" name="validateForm" id="B3" value="Validate data" onclick=validateForm()>
<input type="submit" name="submitForm" id="B2" value="Submit form">
</form>
<script type="application/javascript">
//shows the student checklist div and hides the faculty one
function showStudentDiv() {
document.getElementById("D2").hidden = true;
document.getElementById("D1").hidden = false;
}
//shows the faculty checklist div and hides the student one
function showFacultyDiv() {
document.getElementById("D1").hidden = true;
document.getElementById("D2").hidden = false;
}
//checks if a character is a letter or not
function isLetter(str) {
if (str.length == 1 && str.match(/[a-z]/i)) {
return true;
} else return false;
}
//clears all fields, but does not reset values because values are only updated when trying to be validated
function clearAll() {
//clear the error message field
document.getElementById("D3").innerHTML = "";
//reset each text field to default values
document.getElementById("F1").value = "";
document.getElementById("F2").value = "";
document.getElementById("F3").value = "";
document.getElementById("F4").value = "";
document.getElementById("F5").value = "";
//uncheck the radio buttons and hide the divs they control
document.getElementById("F6").checked = false;
document.getElementById("F7").checked = false;
document.getElementById("D1").hidden = true;
document.getElementById("D2").hidden = true;
//uncheck every checkbox in the divs controlled by radio buttons
document.getElementById("F8").checked = false;
document.getElementById("F9").checked = false;
document.getElementById("F10").checked = false;
document.getElementById("F11").checked = false;
document.getElementById("F12").checked = false;
document.getElementById("F13").checked = false;
document.getElementById("F14").checked = false;
}
//test function to see if the "Validate data" button has scope to this area of code
function validateForm() {
alert("function was called 2");
}
//validates each field in the page and returns true ONLY if every single field is valid
function submitForm() {
alert("function was called");
//validate fields, then submit form
//postal code must be of proper form
//at least one radio button must have "checked == true"
//all text fields must have data in them
var formIsValid = true;
//var whichProblem = "";
//check to ensure the first five fields are not empty
if (document.getElementById("F1").value == "") {
formisValid = false;
errorMessage("F1");
} else if (document.getElementById("F2").value == "") {
formisValid = false;
errorMessage("F2");
} else if (document.getElementById("F3").value == "") {
formisValid = false;
errorMessage("F3");
} else if (document.getElementById("F4").value == "") {
formisValid = false;
errorMessage("F4");
} else if (document.getElementById("F5").value.length != 6) {
formisValid = false;
errorMessage("F5");
}
if (isValidPostalCode(document.getElementById("F5")) == false) {
formIsValid = false;
}
if (document.getElementById("F6").checked == false && document.getElementById("F7") == false) {
formIsValid = false;
}
if (formIsValid == true) {
}
}
//validates a 6-character string as a Canadian postal code: returns false if any character is invalid
//Note: the "doument.write" line at the bottom is a placeholder for testing - in the real assignment, this
//function would simply return true
function isValidPostalCode(postalCode) {
var PC1 = false;
var PC2 = false;
var PC3 = false;
var PC4 = false;
var PC5 = false;
var PC6 = false;
//check to ensure the postal code is of the proper form
//define a list of valid characters for each place in the postal code
var postalChar1 = ['A', 'B', 'C', 'E', 'G', 'J', 'H', 'K', 'M', 'N', 'L', 'P', 'R', 'S', 'T', 'X', 'V', 'Y'];
var postalChar246 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
//check 1st character
for (var i = 0; i < postalChar1.length; i++) {
if (postalCode[0] == postalChar1[i]) {
PC1 = true;
}
}
//check characters 2, 4, and 6 to see if they are numbers 0-9
for (var i = 0; i < postalChar246.length; i++) {
if (Number(postalCode[1]) == postalChar246[i]) {
PC2 = true;
}
}
for (var i = 0; i < postalChar246.length; i++) {
if (Number(postalCode[3]) == postalChar246[i]) {
PC4 = true;
}
}
for (var i = 0; i < postalChar246.length; i++) {
if (Number(postalCode[5]) == postalChar246[i]) {
PC6 = true;
}
}
//check characters 3 and 5 to see if they are letters
if (isLetter(postalCode[2]) == true) {
PC3 = true;
}
if (isLetter(postalCode[4]) == true) {
PC5 = true;
}
//1st is specific letters
//2nd is any number 0-9
//3rd is any letter
//4th is any number 0-9
//5th is any letter
//6th is any number 0-9
if (PC1 == false || PC2 == false || PC3 == false || PC4 == false || PC5 == false || PC6 == false) {
return false;
} else {
document.write("Form submission successful");
}
}
//displays an error message to the user if he entered invalid data, depending on the field
function errorMessage(messageCode) {
if (messageCode == "F1") {
alert("You must enter a name.");
} else if (messageCode == "F2") {
alert("You must enter a street.");
} else if (messageCode == "F3") {
alert("You must enter a city.");
} else if (messageCode == "F4") {
alert("You must choose a province or territory.");
} else if (messageCode == "F5") {
alert("You must enter a valid Canadian Postal code (A#A #A#).");
} else if (messageCode == "F6" || messageCode == "F7") {
alert("You must indicate if you are a student or faculty.");
}
}
</script>
</body>
</html>
ASP:
<!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>WDD : A-02</title>
<style type="text/css">
.style1 { text-align: center; font-family: Calibri, Arial, sans-serif; }
.style2 { font-family: Calibri, Arial, sans-serif; }
td { font-family: Consolas, sans-serif; }
</style>
</head>
<body>
<h1 class="style1"> WDD (PROG2000) : A-02 : The <i>Form Listener</i></h1>
<br />
<h3 class="style2"> Response page for either a GET or POST method.</h3>
<br />
<%
dim i
i=1
if request.querystring<>"" then
response.write "<p class='style2'>You sent data to <i>testRequest.asp</i> using the <b>GET</b> action ... Here is what you sent:<br/><br/></p><div align='center'><table border='0'>"
for each str in request.querystring
response.write "<tr><td width='120' align='right'>Parameter "&CStr(i)&":</td><td width='150' align='right'>"& str & "</td><td width='40' align='center'>=</td><td width='250' align='left'>" & request.querystring(str).Item & "</td></tr>"
i=i+1
next
response.write "</table></div>"
else
if request.form <>"" then
response.write "<p class='style2'>You sent data to <i>testRequest.asp</i> using the <b>POST</b> action ... Here is what you sent:<br/><br/></p><div align='center'><table border='0'>"
for each str in request.form
response.write "<tr><td width='120' align='right'>Parameter "&CStr(i)&":</td><td width='150' align='right'>"& str & "</td><td width='40' align='center'>=</td><td width='250' align='left'>" & request.form(str).Item & "</td></tr>"
i=i+1
next
response.write "</table></div>"
else
response.write "<p class='style2'>Hey ... There is no GET or POST method in use!</p>"
end if
end if
%>
</body>
</html>
解决方案
根据您的描述,我认为这个问题与您的经典 aspo 代码无关。
我建议您可以尝试运行以下命令来检查 iplisten。
运行以下 cmd 命令:
netsh http show iplisten
如果您收到上述命令的输出不是 0.0.0.0,您可以尝试运行以下命令以删除其他 iplisten
netsh http delete iplisten ipaddress=aa.bb.cc.dd (where aa.bb.cc.dd is the IP address that we have to remmove)
netsh http add iplisten ipaddress=0.0.0.0
iisreset
如果这个解决方案不能解决你的问题,我建议你可以参考下面的文章来干净重装 IIS。
https://blogs.msdn.microsoft.com/friis/2017/01/16/how-to-perform-a-clean-reinstallation-of-iis/
推荐阅读
- javascript - Bluebeam 或 Adobe SaveAs 通过使用 JS 的提交按钮
- graph - 3D 图形网络拓扑未知搜索命令拟合
- haskell - ghc 无法编译任何东西并给出看似无关的错误消息
- php - 使用PHP增加变量后如何通过if语句重申?
- javascript - 循环遍历 JSON 数据以将嵌套数据添加到数组(要添加到 MySQL 数据库表)在缺少值时失败
- java - 无法使用 drools 工作台仪表板构建和部署 jar 文件以将其部署到 kieserver。构建 jar spinner 的过程卡住了
- python - Visual Studio Code 不会打开 .py、.ipynb 文件
- wpf - WPF 应用程序未调用 Prism INavigationAware 方法
- android - xamarin form android自定义渲染器:覆盖两个页面
- c# - Github 中的持续部署操作 asp.net 核心解决方案