Sig*_*ard 11 c# asp.net asp.net-mvc user-agent
我遇到一个问题,即移动设备上的用户遇到MVC中的错误,这在常规桌面上查看网站时不会发生.我可以通过使用Chrome的开发人员工具并应用除默认值之外的任何其他UA来始终如一地重现错误.
抛出的基础异常是:
ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.GetExtension(String path)
at System.Web.WebPages.DefaultDisplayMode.TransformPath(String virtualPath, String suffix)
at System.Web.WebPages.DefaultDisplayMode.GetDisplayInfo(HttpContextBase httpContext, String virtualPath, Func'2 virtualPathExists)
at System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath(String virtualPath, HttpContextBase httpContext, Func'2 virtualPathExists, IDisplayMode currentDisplayMode, Boolean requireConsistentDisplayMode)
at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List'1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations)
at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
at System.Web.Mvc.VirtualPathProviderViewEngine.FindPartialView(ControllerContext controllerContext, String partialViewName, Boolean useCache)
at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClass2.<FindPartialView>b__1(IViewEngine e)
at System.Web.Mvc.ViewEngineCollection.Find(Func'2 lookup, Boolean trackSearchedPaths)
at System.Web.Mvc.ViewEngineCollection.FindPartialView(ControllerContext controllerContext, String partialViewName)
at System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions)
at System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate)
at System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData)
at System.Web.Mvc.Html.TemplateHelpers.TemplateFor[TContainer,TValue](HtmlHelper'1 html, Expression'1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper)
at System.Web.Mvc.Html.TemplateHelpers.TemplateFor[TContainer,TValue](HtmlHelper'1 html, Expression'1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData)
at System.Web.Mvc.Html.DisplayExtensions.DisplayFor[TModel,TValue](HtmlHelper'1 html, Expression'1 expression)
使用fiddler时,将成功的请求与失败的请求进行比较时,请求的唯一区别是User-Agent(以及作为查询字符串参数的一部分的jQuery附加的缓存占用者).
为什么只更改UA导致此异常,如何在没有针对每个可能发生和可能发生的地方的特定工作中编写特定的工作?
CSJ*_*CSJ 10
我有完全相同的问题,并修复它.
我的问题原来是yield
在我的viewmodel中使用了一个块:
控制器:
var vm = new BigVM {
SmallVMs = BuildSmallOnes()
};
return View(vm);
private IEnumerable<SmallVM> BuildSmallOnes()
{
// complex logic
yield return new SmallVM(1);
yield return new SmallVM(2);
}
Run Code Online (Sandbox Code Playgroud)
视图:
@model BigVM
@Html.DisplayFor(x => x.SmallVMs) <-- died
Run Code Online (Sandbox Code Playgroud)
令人费解的是,这适用于台式机,但iPad和iPhone失败,引用完全相同的堆栈跟踪.这里和这里报道了类似的问题.通过添加.ToList()
呼叫解决了这个问题,因此:
var vm = new BigVM {
SmallVMs = BuildSmallOnes().ToList()
};
Run Code Online (Sandbox Code Playgroud)
据推测,编译器生成的用于表示yield块的类包括一些用户代理不喜欢的字符.包括ToList()调用使用List <>.
归档时间: |
|
查看次数: |
806 次 |
最近记录: |