【问题标题】:How to disable ASP.NET render default html tag?如何禁用 ASP.NET 呈现默认 html 标记?
【发布时间】:2023-04-03 18:07:01
【问题描述】:

出于某种原因,我必须制作一个 aspx 页面来让 iphone/android 发布表单。 在 request.form 的数据处理之后,我以纯文本形式响应了一个 JSON 字符串。 但是 *.aspx 会强制渲染 html,head,body 标签,那么我该如何禁用它呢?

我无法使用 ashx,因为手机必须通过表单发布图片,因为我通过 google 搜索答案,ashx 无法处理 http 发布文件。

编辑: 正如 SLaks 所说,ashx 可以使用“context.Request.Files”处理 POST 文件,并且可以正常工作。

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    你错了。

    ASHX 文件可以处理 HTTP POST。

    要回答这个问题,您可以删除 ASPX 文件中的所有内容。 ASPX 文件不需要包含任何内容(<%@ Page %> 指令除外)

    【讨论】:

    • 是的。看context.Request.Files。
    【解决方案2】:

    处理帖子时,使用以下代码:

    Response.Clear();
    Response.ContentType = "text/json";
    
    Response.Write("your json goes here");
    
    Response.End();
    

    【讨论】:

      【解决方案3】:

      清除Response,设置内容类型,因为它是json,添加你的json然后结束它:

      protected void Page_Load(object sender, EventArgs e)
      {
          Response.Clear();
          Response.ContentType = "text/json";
          Response.Write("your json");
          Response.End();
      }
      

      准确输出

      your json
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-19
        • 2012-05-27
        • 1970-01-01
        • 2012-01-26
        • 1970-01-01
        • 2011-06-03
        • 2011-07-10
        • 2016-04-02
        相关资源
        最近更新 更多