ContentType on ascx returns 错误

ContentType on ascx returns error

当我尝试在 *.aspx 页面上使用 ContentType 时,它工作正常。

Response.ContentType = ContentType;


但是当我尝试在 *.ascx 上使用时,发生了以下错误:

The name 'ContentType' does not exist in the current context


我应该如何解决这个问题?!

右键单击您的错误和 select Resolve 选项。可能有许多名称空间包含此类型,但 select 您在 aspx.

中使用的名称空间

尝试这样设置(假设我们正在设置 text/plain):

System.Web.HttpContext.Current.Response.ContentType = "text/plain";