为了支持旧版客户端,我们在Windows Server 2012 R2 IIS 8.5.9600.16384上的ASP.Net应用程序中有代码,它只返回“True”或“False”(没有引号):
public partial class Authenticate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["Login"] == "true")
{
var result = Membership.ValidateUser(Request.Form["Username"], Request.Form["Password"]);
if (result)
{
FormsAuthentication.SetAuthCookie(Request.Form["Username"], false);
}
Response.Write(result);
Response.End();
}
}
}
我们安装了一个带有IIS 10.0.14393.0的新Windows Server 2016,现在它正在发回包含在html标签中的值:
"<html><body><p>True</p></body></html>"
为什么??不在我的开发盒或较旧的Win 2012 R2服务器上执行此操作。我找不到任何关于此的信息 - 我们无法更改所有客户端,我们怎样才能确保此网页在Win 2016 IIS 10.0.14393.0上仅返回“True”或“False”?
让它工作,在标题中添加ContentType为text / plain,如下所示:
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "text/plain");
Response.ContentType = "text/plain";
Response.Write(result);
Response.End();