Asp.net mvc 是ASP.NET MVC 4';s Mobile";选择器";这个时候不可靠?

Asp.net mvc 是ASP.NET MVC 4';s Mobile";选择器";这个时候不可靠?,asp.net-mvc,mobile,Asp.net Mvc,Mobile,我这样问是因为我注意到在我的网站上,如果我用iPhone点击它,有时会显示移动视图,有时会显示常规视图 我还读到MVC4在确定浏览器是否来自移动设备方面不是特别有效,是真的吗?如果是这样的话,我们能做些什么吗?更新:微软已经发布了一份针对这个错误的报告 我在 公共类MyDefaultViewLocationCache:DefaultViewLocationCache、IViewLocationCache { 公共MyDefaultViewLocationCache(TimeSpan TimeSp

我这样问是因为我注意到在我的网站上,如果我用iPhone点击它,有时会显示移动视图,有时会显示常规视图


我还读到MVC4在确定浏览器是否来自移动设备方面不是特别有效,是真的吗?如果是这样的话,我们能做些什么吗?

更新:微软已经发布了一份针对这个错误的报告

我在

公共类MyDefaultViewLocationCache:DefaultViewLocationCache、IViewLocationCache
{
公共MyDefaultViewLocationCache(TimeSpan TimeSpan):基本(TimeSpan)
{
}
公共MyDefaultViewLocationCache()
:base()
{
}
公共新字符串GetViewLocation(HttpContextBase httpContext,字符串键)
{
var location=base.GetViewLocation(httpContext,key);
if(位置==null)
{
var cache=httpContext.cache;
RemoveAllCacheStartWith(键,缓存);
}
返回位置;
}
私有静态void RemoveAllCacheStartWith(字符串键,System.Web.Caching.Cache缓存)
{
var keyWithoutDisplayMode=key.Substring(0,key.Substring(0,key.Length-1).LastIndexOf(':')+1);
var items=新列表();
var enumerator=cache.GetEnumerator();
while(枚举数.MoveNext())
{
var_key=enumerator.key.ToString();
如果(_key.StartsWith(keywithout显示模式))
{
项目。添加(_键);
}
}
foreach(项中的字符串项)
{
缓存。删除(项);
}
}
public new void InsertViewLocation(HttpContextBase httpContext,字符串键,字符串virtualPath)
{
InsertViewLocation(httpContext、key、virtualPath);
}
}
//应用内启动
ViewEngines.Engines.OfType().First().ViewLocationCache=
新建MyDefaultViewLocationCache();

有关详细信息,请参见。

您是否总是从同一部iPhone访问您的网站?同一页?@Darin,是的。。。同样的iPhone,同样的页面。即使问题在几次刷新后仍然存在,然后“找到”移动视图。看看这是否有帮助。它讨论了您面临的问题,并使用自定义视图引擎根据请求呈现视图。我们已经确认这是一个错误。该缺陷将在MVC4RTM发布后被修复。
public class MyDefaultViewLocationCache : DefaultViewLocationCache, IViewLocationCache
{
    public MyDefaultViewLocationCache(TimeSpan timeSpan): base(timeSpan)
    {
    }
    public MyDefaultViewLocationCache()
        : base()
    {
    }

    public new string GetViewLocation(HttpContextBase httpContext, string key)
    {
        var location = base.GetViewLocation(httpContext, key);
        if (location == null)
        {
            var cache = httpContext.Cache;
            RemoveAllCacheStartWith(key, cache);
        }
        return location;
    }

    private static void RemoveAllCacheStartWith(string key, System.Web.Caching.Cache cache)
    {
        var keyWithoutDisplayMode = key.Substring(0, key.Substring(0, key.Length - 1).LastIndexOf(':') + 1);
        var items = new List<string>();
        var enumerator = cache.GetEnumerator();
        while (enumerator.MoveNext())
        {
            var _key = enumerator.Key.ToString();
            if (_key.StartsWith(keyWithoutDisplayMode))
            {
                items.Add(_key);
            }
        }
        foreach (string item in items)
        {
            cache.Remove(item);
        }
    }

    public new void InsertViewLocation(HttpContextBase httpContext, string key, string virtualPath)
    {
        base.InsertViewLocation(httpContext, key, virtualPath);
    }
}

// In App Start
ViewEngines.Engines.OfType<RazorViewEngine>().First().ViewLocationCache =
new MyDefaultViewLocationCache();