私は、Ajaxによって実行されるAPIコールにピックアップしますにApp_Codeディレクトリの下にindex.aspxファイルを、持ってしようとしています。ajax呼び出しから(App_Code内の)index.aspxファイルにアクセスしていますか?
例:
(これは、単にその下に1つのindex.aspxファイルとにApp_Codeディレクトリを持っている最後に、index.htmlをがあります。このディレクトリの外のホームページにあるファイル)
背後index.aspxコードフロント
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApplication4.index" runat="server" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index page</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
index.aspxコード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String strAPI = Request.Form["api"];
switch(strAPI)
{
case "test":
Response.Write("It worked!");
break;
}
//lstTest.Items.Add("test");
}
}
}
のindex.htmlコード
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function() {
$.ajax({
url: 'App_Code/',
data: 'api=test',
dataType: 'text',
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
success: function (data)
{
debugger;
},
error: function (data, status)
{
debugger;
}
});
};
</script>
</head>
<body>
<h2>TEST</h2>
</body>
</html>
私はこれを得ています前に仕事をする(しかし、どのように思い出すことはできない)。私が受け取っているエラーは、 'IIS 10.0詳細エラー - 404.8 - 見つかりません' ajax呼び出しのエラーイベントです。基本的には、index.aspxファイルのページロードメソッドには絶対に入りません。
なぜそれをしますか? App_Codeはページ用ではありません – hardkoded