【发布时间】:2017-11-05 13:25:51
【问题描述】:
当用户加载网站的主页(即 index.html 页面)时,我希望我的 index.aspx 也能加载。因此,如果我访问 www.mywebsite.com/index.html,它应该通过 index.aspx.cs 页面(C# 语言)上的 Page_Load 方法运行。
我过去曾这样做过,但我不记得我是如何做到的。最终我想在我的 index.html 页面上执行 ajax 调用......所以我需要检查我在 index.aspx.cs 页面的 Page_Load 方法中进行的 api 调用。
我想我只需要包含runat="server" 就可以了。目前,我只是通过调试器(启动 Chrome)在本地运行页面来测试所有内容。这样不行吗?
ASP 页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="WebApplication1.index" ValidateRequest="false" runat="server" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>wtf</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
ASP 类代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("ASP page loaded.");
}
}
}
index.html 页面:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta charset="utf-8" />
</head>
<body>
index.html page
</body>
</html>
我对使用 ASP 进行设置还是很陌生...所以也许我在这里遗漏了一些东西。谢谢!
【问题讨论】: