数据服务抛出神秘异常:“媒体类型需要 '/'”字符”

发布于 2024-11-18 03:52:33 字数 1209 浏览 2 评论 0原文

在我的网站上加载 ASP.NET 页面时,页面偶尔会失败并在日志中抛出异常:

Media type requires a '/' character

完整的异常如下:

System.Data.Services.DataServiceException: Media type requires a '/' character.     at 
System.Data.Services.HttpProcessUtility.ReadMediaTypeAndSubtype(String text, Int32& 
textIndex, String& type, String& subType)     at 
System.Data.Services.HttpProcessUtility.MimeTypesFromAcceptHeader(String text)     at 
System.Data.Services.HttpProcessUtility.SelectMimeType(String acceptTypesText, String[] 
availableTypes)     at 
System.Data.Services.DataService`1.SelectResponseFormat(DataServiceHostWrapper host,     String 
acceptTypesText, Boolean entityTarget)     at 
System.Data.Services.DataService`1.SelectResponseFormatForType(RequestTargetKind 
targetKind, ResourceType resourceType, String acceptTypesText, String mimeType, 
IDataService service)     at 
System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription     description, 
IDataService dataService)     at System.Data.Services.DataService`1.HandleRequest()

发生故障后,如果我按 F5 刷新,页面会正常加载。如果我尝试重新加载,它稍后会再次失败,但似乎没有任何规律或原因发生这种情况。

我已经进行了网络搜索,但没有找到解决方案。有什么想法吗?

When loading ASP.NET pages on my site, the pages are occasionally failing and throwing exception in my logs:

Media type requires a '/' character

The full exception is as follows:

System.Data.Services.DataServiceException: Media type requires a '/' character.     at 
System.Data.Services.HttpProcessUtility.ReadMediaTypeAndSubtype(String text, Int32& 
textIndex, String& type, String& subType)     at 
System.Data.Services.HttpProcessUtility.MimeTypesFromAcceptHeader(String text)     at 
System.Data.Services.HttpProcessUtility.SelectMimeType(String acceptTypesText, String[] 
availableTypes)     at 
System.Data.Services.DataService`1.SelectResponseFormat(DataServiceHostWrapper host,     String 
acceptTypesText, Boolean entityTarget)     at 
System.Data.Services.DataService`1.SelectResponseFormatForType(RequestTargetKind 
targetKind, ResourceType resourceType, String acceptTypesText, String mimeType, 
IDataService service)     at 
System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription     description, 
IDataService dataService)     at System.Data.Services.DataService`1.HandleRequest()

After the failure occurs, if I hit F5 to refresh, the page loads normally. It will then fail again later if I try to reload but there doesn't appear to be any rhyme or reason why it's happening.

I've done a web search but had no luck in finding a solution. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

并安 2024-11-25 03:52:33

当我向 odata 生产者发布 odata 请求时,我遇到了同样的问题。

最后,我通过添加带有空值的标头“Accept”来解决它,之前省略了该标头。

希望有帮助。

I had the same problem with you when posting an odata request to an odata producer.

Finally I resolved it by adding the header 'Accept' with empty value, which was omitted before.

Hope it helps.

旧伤还要旧人安 2024-11-25 03:52:33

您是否手动设置页面上的 MIME 类型?如果是的话,你可以发布代码吗?听起来您设置它们不正确。

Are you manually setting the MIME types on the page? If so, can you post the code? It sounds like you are setting them incorrectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文