How do you specify your Content Type in ASP.NET WebForms?

♀尐吖头ヾ 提交于 2019-12-08 16:37:31

问题


I'm specifying my doctype as xhtml strict, but it's being sent over the wire as a content type of text/html. I'd like to specify that the content type is application/xhtml+xm, but I can't figure out where, or if, I can configure this from within my application


回答1:


You can specify it in the @ page attributes section, like this:

<%@ Page ContentType="application/xhtml+xm" %>

...more on MSDN.




回答2:


In your code behind file, during the Page_Load event, try addind the following code:

Response.Clear()
Response.ContentType = "application/xhtml+xm"



回答3:


=========aspx===============

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>


<asp:literal runat="server" id="dt"></asp:literal>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

==============code behind=========

protected void Page_Load(object sender, EventArgs e)
{
this.dt.Text= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

}


来源:https://stackoverflow.com/questions/174916/how-do-you-specify-your-content-type-in-asp-net-webforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!