gpt4 book ai didi

c# - 在 Asp.net MVC 中将移动设备的重定向代码放在哪里

转载 作者:太空宇宙 更新时间:2023-11-03 20:28:26 25 4
gpt4 key购买 nike

我从 http://detectmobilebrowsers.com/ 得到了 C# 的检测代码.现在,我不知道把它放在哪里以及如何让它工作。

基本上,我想要的只是我的移动访问者应该被重定向到 http://m.site.com ,我的移动网站所在的位置。让我知道如何通过上述代码或任何其他方法完成此任务。

注意:- 主网站是一个 Asp.net MVC3 应用程序。

最佳答案

我会调用 global.asax Application_BeginRequest 事件中的代码。

void Application_BeginRequest(object sender, EventArgs e)
{
string u = Request.ServerVariables["HTTP_USER_AGENT"];
if (BrowserDetect.IsMobile(u)) //Pretend there is class and function that has all the regex stuff here.
{
Response.Redirect("http://m.site.com");
}
}

关于c# - 在 Asp.net MVC 中将移动设备的重定向代码放在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com