I'm trying to have an index.aspx file under the App_Code directory, which will pick up on api calls performed by ajax.
Example:
(This simply has an App_Code directory with 1 index.aspx file under it. Finally, there is a index.html file outside of this directory for the home page.)
index.aspx code front
<%@ 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 code behind:
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 code
<!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>
I've gotten this to work before (but cannot recall how). The error that I'm receiving is 'IIS 10.0 Detailed Error - 404.8 - Not Found' in the ajax call's error event. Basically it's never getting into the page load method of the index.aspx file.