现在客户有这样一个需求,
www.avene.cn 是用来给电脑访问的 产品 官网,
http://avene.wapg.cn/home/avene/?user=www 是给pc访问的 产品官网 。如果, 用手机访问 www.avene.cn ,那么自动跳转至 http://avene.wapg.cn/home/avene/?user=www 如果,用电脑访问 http://avene.wapg.cn/home/avene/?user=www ,自动跳转至 www.avene.cn 不知道描述清楚没有,请高手赐教?给点具体方案和代码。
www.avene.cn 是用来给电脑访问的 产品 官网,
http://avene.wapg.cn/home/avene/?user=www 是给pc访问的 产品官网 。如果, 用手机访问 www.avene.cn ,那么自动跳转至 http://avene.wapg.cn/home/avene/?user=www 如果,用电脑访问 http://avene.wapg.cn/home/avene/?user=www ,自动跳转至 www.avene.cn 不知道描述清楚没有,请高手赐教?给点具体方案和代码。
我这边也有两个 方法 ,还没测试呢,不知道行不行 if (HttpContext.Current.Request.Headers["user-agent"] != null && HttpContext.Current.Request.Headers["user-agent"].ToLower().ToString().IndexOf("mozilla") != -1)
{
HttpContext.Current.Response.Redirect("http://www.avene.cn/"); //PC }
else
{
HttpContext.Current.Response.Redirect("http://avene.wapg.cn/home/avene/?user=www"); //Mobile ClientTypeTesting. } }
public static boolean choose(String userAgent)
{
if (userAgent.indexOf("Noki") > -1 || // Nokia phones and emulators
userAgent.indexOf("Eric") > -1 || // Ericsson WAP phones and emulators
userAgent.indexOf("WapI") > -1 || // Ericsson WapIDE 2.0
userAgent.indexOf("MC21") > -1 || // Ericsson MC218
userAgent.indexOf("AUR") > -1 || // Ericsson R320
userAgent.indexOf("R380") > -1 || // Ericsson R380
userAgent.indexOf("UP.B") > -1 || // UP.Browser
userAgent.indexOf("WinW") > -1 || // WinWAP browser
userAgent.indexOf("UPG1") > -1 || // UP.SDK 4.0
userAgent.indexOf("upsi") > -1 || //another kind of UP.Browser
userAgent.indexOf("QWAP") > -1 || // unknown QWAPPER browser
userAgent.indexOf("Jigs") > -1 || // unknown JigSaw browser
userAgent.indexOf("Java") > -1 || // unknown Java based browser
userAgent.indexOf("Alca") > -1 || // unknown Alcatel-BE3 browser (UP based)
userAgent.indexOf("MITS") > -1 || // unknown Mitsubishi browser
userAgent.indexOf("MOT-") > -1 || // unknown browser (UP based)
userAgent.indexOf("My S") > -1 ||// unknown Ericsson devkit browser
userAgent.indexOf("WAPJ") > -1 ||//Virtual WAPJAG www.wapjag.de
userAgent.indexOf("fetc") > -1 ||//fetchpage.cgi Perl script from www.wapcab.de
userAgent.indexOf("ALAV") > -1 || //yet another unknown UP based browser
userAgent.indexOf("Wapa") > -1 || //another unknown browser (Web based "Wapalyzer")
userAgent.indexOf("Oper") > -1)
{
return true;
}
else
{
return false;
}原理和你那个类似
http://topic.csdn.net/u/20100907/16/2cdfbfb3-4ae2-490d-acda-a20d5533b50d.html
1. 手机通过wap上网可能会被wap网关滤掉UA
2. UA信息未必准确建议,只判断PC用户,其他未被归类于PC的,作为手机用户处理
我下面这个方法就是这种思路,手机的浏览器很多很杂,毕竟无法全部包含。
判断pc的话,具体该怎么判断呢? if (HttpContext.Current.Request.Headers["user-agent"] != null && HttpContext.Current.Request.Headers["user-agent"].ToLower().ToString().IndexOf("mozilla") != -1)
{
HttpContext.Current.Response.Redirect("http://www.avene.cn/"); //PC }
else
{
HttpContext.Current.Response.Redirect("http://avene.wapg.cn/home/avene/?user=www"); //Mobile ClientTypeTesting. }
若是非Windows系统,只能用浏览器关键字了,毕竟很多手机操作系统都是Linux内核,例如“Firefox”等等
公网的ip是一样的,这个方案刚开始就被 pass 掉了
http://avene2009.nurunci.com
如果是pc ,就不会跳转
没有吧。 我只是让用户访问 http://avene2009.nurunci.com 这个地址啊。我的程序会根据 用户 用户 是使用的pc还是手机,进行相应的跳转啊,怎么叫把 “把选择权还给用户”
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error:
//我的问题还没解决求助中...
protected void Page_Load(object sender, EventArgs e)
{
HttpCapabilitiesBase r = (System.Web.Configuration.HttpCapabilitiesBase)Request.Browser;
string agent = (Request.UserAgent + "").ToLower().Trim();
if (r.Browser == "Mozilla")
Response.Write("可以识别:Mozilla");
else
Response.Write("不识别:Mozilla");
if (r.IsMobileDevice || r.Browser == "Unknown" || r.Browser == "Mozilla")
{
Response.Write("手机" + "\r\n" + r.Browser + "\r\n" + r.Type);
}
else
{
Response.Write("电脑" + "\r\n" + r.Browser + "\r\n" + r.Type);
}
}