可能导致XML解析错误的原因:找不到任何元素?

And*_*ers 19 asp.net

我最近将一个ASP站点从我的dev机器迁移到了一个实时服务器.除了我的FAQ页面以外的所有页面都运行正常,但我的常见问题解答提出:

XML Parsing Error: no element found
Location: http://geniusupdate.com/GSHelp/faq.aspx
Line Number 1, Column 1:
Run Code Online (Sandbox Code Playgroud)

我所做的唯一更改是将我的SQL页面上的连接字符串从本地更改为我的托管服务指定的字符串.有关如何找到问题的根源的任何提示?

这是我的FAQ页面的来源:

<%@ 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>
Run Code Online (Sandbox Code Playgroud)

我在另一个论坛链接上找到了这个:

好吧,它似乎有点兼而有之.该消息由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
Run Code Online (Sandbox Code Playgroud)

这里是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>
Run Code Online (Sandbox Code Playgroud)

Ric*_*ich 16

这是一个非常古老的主题,但我在谷歌搜索同样的问题时发现了这一点,并希望为将来搜索此内容的其他人提供明确的答案.

在解析页面指令时抛出异常时出现此错误.我从源代码管理中更新了aspx文件,检查它们的开发人员使用了不同版本的第三方控件库.Register Assembly页面指令引用了我没有的版本,因此此时抛出了异常.我假设当在页面请求生命周期中如此早地抛出异常时,在客户端中出现此错误时,根本没有任何内容被发送到客户端.

我们正在应用程序级别记录所有异常Global.Application_Error,因此我能够从日志中获取此信息.我们使用以下代码获取最后一个异常:

Server.GetLastError().GetBaseException()
Run Code Online (Sandbox Code Playgroud)


yka*_*ich 6

我对ASP.NET一无所知,但根据我对Web框架的一般经验,听起来你的应用程序根本没有产生任何输出.通常这意味着在任何输出呈现发生之前都存在异常,因此请尝试查看日志以找出导致它的原因...


kyl*_*leb 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);
}
Run Code Online (Sandbox Code Playgroud)


Chr*_*nce 1

开头没有 xml 声明

<?xml 版本=“1.0”?>