1

我使用 Index.cshtml 和 Index.mobile.cshtml。我的 Index.cshtml 是一个包含 iframe 的移动应用登录页面,用于现场演示移动 Web 应用。Index.mobile.cshtml 是移动网络应用程序本身。

问题是,iframe 不断加载桌面版本本身。据我所知,我无法将 iframe 的用户代理配置为移动类型。它应该可以通过一些路由来解决,但我不知道怎么做!?

更新

我想我找到了解决办法。在 iFrame src 中,我引入了一个 URL 参数 forceMobile=true :

<iframe id="rtnApp" src="/demohcid?forceMobile=true"></iframe>

现在在 HomeController 中,我检查此 URL 参数,如果是 forceMobile,则返回移动视图,即使代理是桌面浏览器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        if (Request.Params["forceMobile"] != null) 
            return View("Index.mobile");
        else {
            return View();
        }
    }
4

0 回答 0