简体   繁体   English

呈现不带HTML,正文标签的.aspx页面

[英]Render .aspx page without html, body tags

I have a test page Test.aspx , below is the code i have it in Page_Load function. 我有一个测试页Test.aspx ,以下是我在Page_Load函数中拥有的代码。

Response.Write("test");

When i execute this page, i can see the html out put "test" along with html, body tags in it. 当我执行此页面时,我可以看到html输出“ test”以及其中的html,body标签。

What should i do so that the output only has the text "test", and no body,html tags? 我应该怎么做才能使输出仅包含文本“ test”,而没有body,html标记?

Please suggest. 请提出建议。

You can try with this code - based on ContentType = "text/plain"; 您可以尝试使用此代码-基于ContentType = "text/plain";

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Only text is printed");
Response.End(); 

Try this 尝试这个

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Test");
Response.End();

When you have a case that you wont an empty page that you can write just some words, or something else, is better to use a handler .ashx 当您遇到一个空白页的情况时,您可以只写一些单词或其他内容,最好使用处理程序.ashx

The handler is not add anything by default, like an .aspx page do, no need to clear anything and you do not spend time to render, then clear as you do with an aspx page. 默认情况下,该处理程序不会添加任何内容,就像.aspx页面一样,无需清除任何内容,并且您无需花费时间进行渲染,然后像处理aspx页面一样进行清除。

So the correct way, is to create a handler. 因此正确的方法是创建一个处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM