数据服务抛出神秘异常:“媒体类型需要 '/'”字符”
在我的网站上加载 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我向 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.
您是否手动设置页面上的 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.