gpt4 book ai didi

asp.net - 什么可能导致 XML 解析错误 : no element found?

转载 作者:行者123 更新时间:2023-12-03 12:34:00 25 4
gpt4 key购买 nike

我最近将一个 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 :

Well, it appears it's a bit of both. The message is generated by Firefox, but caused by the framework. For some reason, .NET generates a response type of "application/xml" when it creates an empty page. Firefox parses the file as XML and finding no root element, spits out the error message.



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>

最佳答案

我遇到了这个问题,至少对我来说发现这是因为在 C# WebAPI 2 中,如果您返回一个空的 Ok() 结果,它将返回 XML 作为内容类型。即使您在 WebAPI 配置中覆盖它以永远不返回 XML。所以我的解决方案是在我拥有的基本 Controller 类中创建这个函数,并在需要返回空 OK() JSON 响应的任何地方使用它。可以根据他们的需要使其更先进,但这就是我所做的。我想你也可以使用 AttributeFilter,但我做了这个解决方案,因为它在 Action 中的代码数量相同。

protected IHttpActionResult OKJSONResult()
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "", new MediaTypeHeaderValue("application/json"));
return ResponseMessage(response);
}

关于asp.net - 什么可能导致 XML 解析错误 : no element found?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/303066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com