我的MVC3项目有一个叫做Mobile的区域。以下是从桌面浏览器和移动浏览器访问我的站点时的行为:
无论是从桌面浏览器还是移动浏览器中查看,我都希望URL保持mydomain.com。我该怎么做呢?
发布于 2011-04-05 04:00:48
尝试为移动设备使用ActionName过滤器和自定义操作方法选择器。示例(复制自“Pro ASP.NET MVC 2”一书,第351页):
- In Controller define 2 function for desktop & iPhone, they have the same ActionName
[iPhone]
[ActionName("Index")]
public ActionResult Index_iPhone() { /* Logic for iPhones goes here */ }
[ActionName("Index")]
public ActionResult Index_PC() { /* Logic for other devices goes here */ }
- Define [iPhone] action method selector:
public class iPhoneAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(ControllerContext controllerContext,
MethodInfo methodInfo)
{
var userAgent = controllerContext.HttpContext.Request.UserAgent;
return userAgent != null && userAgent.Contains("iPhone");
}
}发布于 2011-04-05 02:29:19
https://stackoverflow.com/questions/5546501
复制相似问题