如何使用ASP.NET确定请求是来自移动应用程序还是移动浏览器 [英] How to identify whether the request is from a mobile application or mobile browser using ASP.NET
本文介绍了如何使用ASP.NET确定请求是来自移动应用程序还是移动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能帮我识别一下来自应用程序或手机浏览器的请求吗?
我尝试了什么:
我还没有得到任何东西。我是 Request.UserAgent
。但是不知道如何继续这个。
Can you help me to identify the request is from application or mobile browser?
What I have tried:
I did not got anything yet. I was Request.UserAgent
. But did not know how to proceed with this.
推荐答案
一个简单的搜索产生:
ASP.NET移动设备检测 [ ^ ]
基于http请求检测Web应用程序中移动浏览器的标准方法 - 堆栈溢出 [ ^ ]
vb.net - 检查移动浏览器是否正在访问网站 - Stack Overflow [ ^ ]
检测移动浏览器(移动设备)在ASP.Net中使用C#和VB.Net [ ^ ]
A simple search yields:
ASP.NET Mobile Device Detection[^]
Standard way to detect mobile browsers in a web application based on the http request - Stack Overflow[^]
vb.net - Checking if mobile browser is acessing site - Stack Overflow[^]
Detect Mobile Browser (Mobile Device) in ASP.Net using C# and VB.Net[^]
你能在BasePublicController.cs中尝试这段代码吗?
受保护覆盖ViewResult视图(IView视图,对象模型)
{
返回base.View (查看,型号);
}
受保护的覆盖ViewResult视图(字符串viewName,字符串masterName,对象模型)
{
string action = this.ControllerContext.RouteData.Values [action]。 ToString();
if(Request.Browser.IsMobileDevice&& Request.HttpMethod ==Get)
{
Response.Write(mobile);
return View(action); < br $>
}
else
{
Response.Write(desktop) ;
返回查看(操作);
}
}
Can you try this code in BasePublicController.cs
protected override ViewResult View(IView view, object model)
{
return base.View(view, model);
}
protected override ViewResult View(string viewName, string masterName, object model)
{
string action = this.ControllerContext.RouteData.Values["action"].ToString();
if (Request.Browser.IsMobileDevice && Request.HttpMethod == "Get")
{
Response.Write("mobile");
return View(action);
}
else
{
Response.Write("desktop");
return View(action);
}
}
这篇关于如何使用ASP.NET确定请求是来自移动应用程序还是移动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文