iT邦幫忙

1

[ASP.NET]head 中的內容跑到 body 裡

  • 分享至 

  • xImage

index.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="test123.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <span id="message" runat="server"></span>
        </div>
    </form>
</body>
</html>

index.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace test123
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("Hello World by string<br>");
            string hello = "Hello World by Variables";
            Response.Write(hello);
        }
    }
}

chrome用F12看的html

<html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    </head>
    
    <body>
        Hello World by string
        <br>
        Hello World by Variables
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>
        </title>
        <form method="post" action="./index.aspx" id="form1">
            <div class="aspNetHidden">
                <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="O9WYoaTC5iwbsFsB2mCEOnqz68K/nxGNnlZpDQrH7RPw/gHG3Z12Y/YwMo15r4sddiL2iIJAvMBQMvr5vJaHZ8znO/ZowoGE8Lt/xVcxZuE=">
            </div>
            <div class="aspNetHidden">
                <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR"
                value="90059987">
            </div>
            <div>
                <span id="message">
                </span>
            </div>
        </form>
    </body>

</html>

Q:為什麼head的東西跑到body內了?(如<title><meta>)

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
glj8989332
iT邦研究生 4 級 ‧ 2020-07-17 13:18:02
最佳解答

其實你仔細看Chrome的Sources頁籤

它原始長這樣

Hello World by string<br>Hello World by Variables

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>

</title></head>
<body>
    <form method="post" action="./WebForm1" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="97jk6dKQ23Tl/BEXuw8iffm9h6XiskHKWbsN8+zy95WX64LFH4cORkqYphXFjLfWA+Jh7SEOUQSQAu+DxKDYMRitDgJuCvxWyRe7mF58SzM=" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="C687F31A" />
</div>
        <div>
            <span id="message"></span>
        </div>
    </form>
</body>
</html>

由於你輸出Hello World by string字串讓整個HTML結構異常, Chrome會再整理成它可以理解的格式

wrxue iT邦好手 1 級 ‧ 2020-07-17 13:23:46 檢舉

原來是這樣,謝謝您了!

我要發表回答

立即登入回答