Asp.net Visual Studio 2013预览及更新:ASPX视图引擎插入额外空间
我们的应用程序使用简单的aspx语法来显示服务器的版本,例如:Asp.net Visual Studio 2013预览及更新:ASPX视图引擎插入额外空间,asp.net,iis-express,visual-studio-2013,Asp.net,Iis Express,Visual Studio 2013,我们的应用程序使用简单的aspx语法来显示服务器的版本,例如: <h1>Server Engine v<%=System.Reflection.Assembly.GetAssembly(typeof(Server.Engine)).GetName().Version %></h1> // "Server Engine v3.6.1268.0" 从VS2012开始,同样的项目运行良好。为什么会发生这种情况以及如何避免这种问题 更新1: 以下是十六进制视图中的这
<h1>Server Engine v<%=System.Reflection.Assembly.GetAssembly(typeof(Server.Engine)).GetName().Version %></h1>
// "Server Engine v3.6.1268.0"
从VS2012开始,同样的项目运行良好。为什么会发生这种情况以及如何避免这种问题
更新1:
以下是十六进制视图中的这些奇怪符号:
00000002E0: 3A 27 20 2B 20 70 6F 72 │ 74 20 2B 20 27 EF BB BF :' + port + 'п»ї
00000002F0: EF BB BF EF BB BF EF BB │ BF EF BB BF 2F 27 3B 0A п»їп»їп»їп»ї/';◙
更新2:
我补充说:
<%=System.Diagnostics.Process.GetCurrentProcess().MainModule.FileVersionInfo %>
只有当我选择“修改”时,问题才能重现
更新5:
下面是一个简单的复制示例:
using System.Web;
using System.Web.UI;
namespace WebApplication2
{
public class DavHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.BufferOutput = false;
Page page = (Page)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(
"~/MyCustomHandlerPage.aspx", typeof(Page));
page.ProcessRequest(HttpContext.Current);
}
}
}
MyCustomHandlerPage.aspx:
<%@ Page Title="WebDAV" Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>IT Hit WebDAV Server Engine</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body { font-family: Verdana; font-size:smaller; }
li { padding-bottom: 7px; }
input {width: 250px}
</style>
</head>
<body>
<p>"<%="TEST" %>"</p>
</body>
</html>
它击中了WebDAV服务器引擎
正文{字体系列:Verdana;字体大小:较小;}
li{填充底部:7px;}
输入{宽度:250px}
“”
Web.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="RepositoryPath" value="~/App_Data/WebDAV/Storage"/>
</appSettings>
<system.web>
<customErrors mode="Off"/>
<authentication mode="None"/>
<authorization>
<allow users="*"/>
</authorization>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<compilation targetFramework="4.0" debug="true"/>
</system.web>
<system.webServer>
<handlers>
<clear />
<add name="My WebDAV Handler" path="*" verb="*" type="WebApplication2.DavHandler, WebApplication2" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
如果在Internet Explorer中从Visual Studio 2013运行此示例,并查看生成页面的源代码,您将看到:
<p>" TEST "</p>
“测试”
然后,您可以将页面另存为文件,并使用HEX viewer查看它。您将看到插入的字节顺序标记“EF BB BF”。但不适用于任何其他Visual Studio版本
更新6:
此问题在VS 2013中以debug=“true”模式创建项目时出现。当我从VS2010/2012打开此项目时,同样的问题也出现了。
但是当项目在VS2010/2012中创建时,问题就不存在了。您可以在这里下载示例:Visual Studio 2013 RC中没有问题。
using System.Web;
using System.Web.UI;
namespace WebApplication2
{
public class DavHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.BufferOutput = false;
Page page = (Page)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(
"~/MyCustomHandlerPage.aspx", typeof(Page));
page.ProcessRequest(HttpContext.Current);
}
}
}
<%@ Page Title="WebDAV" Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>IT Hit WebDAV Server Engine</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body { font-family: Verdana; font-size:smaller; }
li { padding-bottom: 7px; }
input {width: 250px}
</style>
</head>
<body>
<p>"<%="TEST" %>"</p>
</body>
</html>
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="RepositoryPath" value="~/App_Data/WebDAV/Storage"/>
</appSettings>
<system.web>
<customErrors mode="Off"/>
<authentication mode="None"/>
<authorization>
<allow users="*"/>
</authorization>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<compilation targetFramework="4.0" debug="true"/>
</system.web>
<system.webServer>
<handlers>
<clear />
<add name="My WebDAV Handler" path="*" verb="*" type="WebApplication2.DavHandler, WebApplication2" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
<p>" TEST "</p>