当用户关闭浏览器时,我试图在我的 aspx.cs 中调用服务器方法来删除目录中的所有文件。
[WebMethod]
    public static void fileDelete()
    {
        string[] uploadedFiles = Directory.GetFiles(@"C:\Users\Lambo\Documents\Visual Studio 2010\Projects\test\test\testPdfIn");
        foreach (string uploaded in uploadedFiles)
        {
            File.Delete(uploaded);
        }
    }
==================================================== =====================
编辑
我已经尝试过 POST 方法,但它似乎仍然不起作用。我也改了网址。
在客户端我使用这个:
    $(function () {
        $(window).unload(function () {
            alert("Files have been deleted")
             jQuery.ajax({ type: 'POST', url: "http://localhost:19642/success.aspx/fileDelete", async: true });
        });
    });
但是它似乎没有工作。代码在某种程度上是错误的吗?