我最近将ASP网站从我的开发机器迁移到了实时服务器。除了我的常见问题解答页面之外的所有页面都运行正常,但我的常见问题解答显示:
XML Parsing Error: no element found
Location: http://geniusupdate.com/GSHelp/faq.aspx
Line Number 1, Column 1:
我所做的唯一更改是将我的SQL页面上的连接字符串从本地更改为我的托管服务指定的字符串。我可以做些什么来找到这个问题的根源?
这是我的常见问题解答页面的来源:
<%@ Page Language="VB" MasterPageFile="~/theMaster.master" AutoEventWireup="false" CodeFile="faq.aspx.vb" Inherits="faq" Title="Untitled Page" %>
<%@ Import Namespace="sqlstuff" %>
<%@ Import Namespace="functions" %>
<asp:Content ContentPlaceHolderID="page_title" ID="theTitle" runat="server">
FAQ</asp:Content>
<asp:Content ContentPlaceHolderID="column1_title" ID="col1Title" runat="server">
<%=faqPageTitle(Request.QueryString("cid"))%></asp:Content>
<asp:Content ContentPlaceHolderID="column1" ID="columnContent" runat="server">
<p>Click on a question to expand it to see the answer!</p>
<p><% If cID >= 0 Then
Dim theFaq As New List(Of faqContent), iterate As Integer = 0
theFaq = sqlStuff.getFaqs(cID)
For Each oFaq As faqContent In theFaq
Response.Output.WriteLine("<h4 id={0} class={1}>Q: {2}</h4>", _
addQuotes("gsSwitch{0}-title", iterate), _
addQuotes("handCursor"), _
oFaq.Content.Question)
Response.Output.WriteLine("<div id={0} class={1}><string>A: </strong>{2}</div>", _
addQuotes("gsSwitch{0}", iterate), _
addQuotes("gsSwitch"), _
oFaq.Content.Answer)
iterate += 1
Next
Else
Response.Output.Write("Here you can find a lot of information about eTHOMAS and how to expedite your office tasks.{0}", ControlChars.NewLine)
End If
%></p>
<script type="text/javascript">
var gsContent = new switchcontent("gsSwitch", "div")
var eID = '<%= expandID %>'
gsContent.collapsePrevious(true) // TRUE: only 1; FALSE: any number
gsContent.setPersist(false)
if(eID >= 0){
gsContent.defaultExpanded(eID) // opens the searched FAQ
document.getElementById('gsSwitch' + eID + '-title').scrollIntoView(true) // scrolls to selected FAQ
}
gsContent.init()
</script>
</asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_right_title" ID="rSideColTitle" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_right" ID="rSideColContent" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_left_title" ID="lSideColTitle" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_left" ID="lSideColContent" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="sidecolumn_title" ID="sideColtitle" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="sidecolumn" ID="sideCol" runat="server">
<% If cID >= 0 Then
Response.Write(constructFaqSideMenu(CInt(Request.QueryString("cid"))))
Else
Response.Write(constructFaqSideMenu())
End If
%>
</asp:Content>
我在另一个论坛link找到了这个:
嗯,看来这两者都有点。该消息由Firefox生成,但由框架引起。出于某种原因,.NET在创建空页面时会生成响应类型“application / xml”。 Firefox将文件解析为XML并找不到根元素,并吐出错误消息。
IE无法呈现页面,期间。这就是XML的来源。
这是constructFaqSideMenu()函数:
Public Shared Function constructFaqSideMenu(ByVal oSelID As Integer) As String
Dim oCatList As New List(Of faqCategory)
Dim oRet As New StringBuilder
Dim iterate As Integer = 1, extraTag As String = ""
oCatList = sqlStuff.getFaqCats
oRet.AppendFormattedLine("<ul id={0}>", addQuotes("submenu"))
oRet.AppendFormattedLine(" <li id={0}>FAQ Categories</li>", addQuotes("title"))
For Each category As faqCategory In oCatList
If iterate = oSelID Then
extraTag = String.Format(" id={0}", addQuotes("active"))
Else
extraTag = ""
End If
oRet.AppendFormattedLine(" <li{0}><a href={1}>{2}</a></li>", extraTag, addQuotes("faq.aspx?cid={0}", iterate), StrConv(category.Title, VbStrConv.ProperCase))
iterate += 1
Next
oRet.AppendLine("</ul>")
Return oRet.ToString
End Function
以下是IE返回的空白页面的来源:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
答案 0 :(得分:16)
这是一个非常古老的主题,但我在谷歌搜索同样的问题时发现了这一点,并希望为将来搜索此内容的其他人提供明确的答案。
在解析页面指令时抛出异常时出现此错误。我从源代码控制中更新了aspx文件,并且检查它们的开发人员拥有不同版本的第三方控件库。 Register Assembly页面指令引用了我没有的版本,因此此时抛出了异常。我假设在页面请求生命周期中如此早地抛出异常时,客户端会显示此错误,并且没有任何内容发送到客户端。
我们正在Global.Application_Error
的应用级别记录所有异常,因此我可以从日志中获取此信息。我们使用以下代码获取最后一个异常:
Server.GetLastError().GetBaseException()
答案 1 :(得分:6)
我对ASP.NET一无所知,但从我对Web框架的一般经验来看,听起来你的应用程序根本无法产生任何输出。通常这意味着在任何输出渲染发生之前都存在异常,因此请尝试查看日志以找出导致它的原因...
答案 2 :(得分:5)
我跑到这里,发现至少对我来说这是因为在C#WebAPI 2中,如果你返回一个空的Ok()结果,它会返回XML作为内容类型。即使您在WebAPI配置中覆盖它也不会返回XML。所以我的解决方案是在我拥有的基本控制器类中创建此函数,并在需要返回空的OK()JSON响应的任何地方使用它。人们可以根据他们的需求使其更先进,但这就是我所做的。我想你也许也可以使用一个AttributeFilter,但是我做了这个解决方案因为它在Action中的代码量相同。
protected IHttpActionResult OKJSONResult()
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "", new MediaTypeHeaderValue("application/json"));
return ResponseMessage(response);
}
答案 3 :(得分:2)
当我部署到IIS时,我的所有页面都出现此问题,解决方案结果显示,运行应用程序池的帐户没有足够的权限来连接和执行数据库查询
答案 4 :(得分:1)
开头没有xml声明
&lt;?xml version =“1.0”?&gt;
答案 5 :(得分:1)
也许有些编码问题,文件开头的“unicode序列”损坏或者这种性质的东西?
答案 6 :(得分:1)
嘿同样的错误发生在我身上,这个错误的解决方案是首先打开iis管理器然后在服务器名称下的iis管理器中双击Web服务扩展,如果您的活动服务器页面被“禁止”,则将其更改为“允许”,现在你的asp页面将会运行。
答案 7 :(得分:1)
如果从.aspx页面调用.vb或.cs脚本并出现此错误,请将以下代码添加到.aspx页面。 FireFox显然需要一些有效标记。这对我有用。
<html>
<body></body>
</html>
答案 8 :(得分:1)
我有同样的问题。这是因为我处理了global.asax中的异常,并调用了Server.ClearError(),而没有调用Response.Redirect或类似的。我想,代码失败并且错误已被删除,因此asp.net无法显示错误消息,也无法显示请求的页面。
我也收到了这个错误,因为我覆盖了页面的render方法,忘了调用base.render(writer),因此向浏览器发送一个空页面。
答案 9 :(得分:1)
我发现此问题是因为网址已重定向到其他位置。纠正解决了这个问题。
它正在重定向到http://localhost/forms/abc.aspx
,但它应该已重定向到http://localhost/projectname/forms/abc.aspx
答案 10 :(得分:1)
我遇到了同样的问题。我的解决方案可能不适用于ASP.NET,我在node / express land工作。我的API端点未在响应中返回任何数据:
return res.status(200).end();
当我在数据响应中包含某些内容时,它解决了问题:
return res.status(200).send('ok').end();
答案 11 :(得分:0)
也许没有XML(XML是一个空白字符串)?
答案 12 :(得分:0)
该站点是用ASP.NET开发的,而不是XML。这与问题有关吗?
答案 13 :(得分:0)
这可能有两个原因。您可能有一个或多个未公开的HTML标记,或者您可能没有为我们的响应设置内容类型。请阅读http://chiragrdarji.wordpress.com/2010/02/17/xml-parsing-error-no-element-found/了解更多详情。
答案 14 :(得分:0)
在新虚拟机上安装我的服务时遇到了这个问题。 (即;尚未在此计算机上运行其他WCF服务。)
您需要安装WCF服务并将其添加到IIS中。最简单的方法如下:
使用提升的管理员权限运行命令提示符
在命令提示符中,导航到C:\ Windows \ Microsoft.NET \ Framework \ v3.0 \ Windows Communication Foundation
运行命令Integer[] myArr = {1,1,1,2,3,4,5,5};
System.out.println("Sum = " + new HashSet<Integer>(Arrays.asList(myArr)).size());
通过运行命令ServiceModelReg.exe -i