asp.net 如何实现网址自动判断并跳转?

作者&投稿:自菲 (若有异议请与网页底部的电邮联系)
怎么让网站自动识别设备,自动跳转wap页面~

自动识别跳转,主要有以下几种方法可以尝试:
1、在网站head标签里加跳转语句
要实现网站根据访问设备自动识别展示手机站或PC站这个功能,需要以下几个步骤:
(1)、你得有一个PC端,在电脑上访问的官方网站,比如:www.baidu.com。
(2)、你需要重新制作一个移动端的手机网站,比如:m.baidu.com。
(3)、在PC端的网站上加上一段代码,每个页面都需要加上,放在PC端网站head标签里面,代码如下:
//平台、设备和操作系统
var system = {
win: false,
mac: false,
xll: false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf(“Win”) == 0;
system.mac = p.indexOf(“Mac”) == 0;
system.x11 = (p == “X11″) || (p.indexOf(“Linux”) == 0);
//跳转语句
if (!(system.win || system.mac || system.xll)) {//转向电脑界面
window.location.href = “http://m.baidu.com”;
}
(4)、进入域名解析系统,做一个别名cname解析,比如:你手机网站制作公司给的地址123.域名.com解析到m.baidu.com域名解析系统。
2、根据移动终端和浏览器版本信息判定的语法
还有一些站长或SEO可能会考虑到移动终端的版本和浏览器版本信息,对此,肥猫科技也为大家整理了一段比较有效的代码,如下所示:

var browser={
versions:function(){
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端
ios: !!u.match(/i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || (u.indexOf('Mac') > -1 && u.indexOf('Macintosh') < 0), //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}(),
language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
if (browser.versions.ios||browser.versions.android||browser.versions.iPhone||browser.versions.iPad) {
self.location=http://www.baidu.com;
}

3、自动识别手机页面、iPad页面和wap页面
可以根据不同的终端类型适当的改变正则表达式,这段代码添加到需要识别的网页,会根据客户端的类型自动跳转到手机页、平板页或其他移动设备页面,非常的灵活!

if(/AppleWebKit.*mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://www.baidu.com/m";
}else if(/iPad/i.test(navigator.userAgent)){
window.location.href="http://www.baidu.com/pad";
}else{
window.location.href="http://www.baidu.com/wap"
}
}catch(e){}
}
}

4、使用PHP语言来识别
对于一些精通PHP语言的博友来说,也可以通过PHP语法来实现,比如以下的写法:
//设定Mobile的定义
$mobileAgent = array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
//读取用户的浏览器资料
$browser = $_SERVER['HTTP_USER_AGENT'];
$isMobile = false;
//检查开始
foreach($mobileAgent as $search){
if(stristr($browser,$search)!=false){
$isMobile = true;
//echo $search;
//程式码(转址)
header("Location: http://www.baidu.com/m/index.html");
//停止运行程序
exit;
}
}
?>
5、做个自动识别的效果
经过多次测试,我们也可以做个自动识别的效果,方法很简单,在你需要自动跳转的页面加入以下代码:

var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i=0; i<mobileAgent.length; i++){ if (browser.indexOf(mobileAgent[i])!=-1){ isMobile = true;
//alert(mobileAgent[i]);
location.href = 'http://siteapp.baidu.com/webapp/mahaixiang.cn#m/http://mahaixiang.cn/';
break; } }

6、自动识别移动端适配跳转网址的代码
手机版的网站需要简单,以文字为主,才能很好的兼容,可以在网站的首页设置一个程序来判断用户是手机端还是电脑,如果是手机端,直接中转到手机端,如果是电脑端,直接中转到电脑端(大家也可以使用百度提高的百度移动搜索开放适配服务。
对此,大家可以在网站的首页插入入下代码:
  
function browserRedirect() {  
var sUserAgent = navigator.userAgent.toLowerCase();  
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";  
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";  
var bIsMidp = sUserAgent.match(/midp/i) == "midp";  
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";  
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";  
var bIsAndroid = sUserAgent.match(/android/i) == "android";  
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";  
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";  
if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){  
window.location.href=B页面; 
}
} 
browserRedirect(); 

uaredirect("<A href='http://www.baidu.com/wap/","http://www.baidu.com/index.html");http://www.baidu.com/wap/","http://www.baidu.com/index.html");

在肥猫科技看来,PC版网页自动识别手机客户端并跳转,用js进行判断是否手机客户端进行跳转最好,特别是静态网页,把这个过程通过js的方式放在用户客户端执行,可以大大减少服务器端额外处理的压力,但是有时需要通过在服务器端进行判断的情况除外。

登录成功的话你就可以存用户到session,在进入用户后台界面时候你可以判断用户的session存不存在,不存在就跳转到登录界面

if (Request.Url.AbsoluteUri.Contains("http://www.bbb.com"))
{
Response.Redirect(Request.Url.AbsoluteUri.Replace("http://www.bbb.com","http://www.aaa.com");
}
这样能把所以访问www.bbb.com的都重定向到www.aaa.com.
把这些代码放到页面的load事件里面就行。

c#有个类可以专门获取、操作url的类,比如Request.ServerVariables["URL"];
然后对比一下是不是你想要的url 不是就跳转。。。不过首先你得对2个站都有
操作权限,就是楼上说的,aaa.com和bbb.com都是你得么?

我这个可以实现批量替换,自动更新文件我用vb6编的,加一个按钮,及file控件 delphi的memo可以用来读取,然后在memo内处理,应该简单得多,或者直接读出来 ad

首先我想问下你,这里两个网站aaa.com和bbb.com都是你自己的网站吗?如果aaa.com这个不是你自己的网站,那么你是没办法让他跳到你自己的网站bbb.com上的!


修武县19519252327: 在ASP网页中怎么自动识别URL?
籍平复方: 做个绑定即可,在你要连接的标签那的href属性里绑定,比如然后在后台设置属性 public string url; 最后在你提交事件里面给这个属性附上你输入的地址就可以拉.

修武县19519252327: 在ASP网页中怎么自动识别URL?在表单中输入如:www./ftp./.com/.cn等就可以自动生成超链接
籍平复方: 这个打开那个就可以了

修武县19519252327: ASP语言手机如何自动识别手机网站,求代码 -
籍平复方: <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=3.0, user-scalable=no"/> <meta name="format-detection" content="telephone=no"/> 把这段话加进去就好了.

修武县19519252327: ASP中自动识别URL的问题?~~ -
籍平复方: <script language="javascript"> function ck() { window.open("http://www."+document.url_name.value+".com"); }</script><input type="text" name="url_name" id="url_name"><input type="button" name="tijiao" id="tijiao" onclick="ck()"> 不是用asp做的 不知道可不可以 自己再做下小的改动 估计应该能满足你的要求吧

修武县19519252327: asp 怎么判断一个网址是否可以打开? -
籍平复方: function getXML(URL) { var xmlhttp = new ActiveXObject("microsoft.xmlhttp"); xmlhttp.Open("GET",URL, false); try { xmlhttp.Send(); } catch(e){} finally { var result = xmlhttp.responseText; if(result) { if(xmlhttp.Status==200) { return(true); } else { ...

修武县19519252327: 在ASP中如何实现自动打开一个新的网页? -
籍平复方: response.redirect"go.htm?u="&rs("homepage")&" end if%>TD>

修武县19519252327: ASP怎么实现输入后自动获取内容? -
籍平复方: 那么看了你的问题<br>ajax是必须用的了.<br>首先触发onblur="FnAjax()"事件//失去焦点触发事件<br>设置div id="divName"<br>那么下面使用ajax函数<br>function FnGetAjax(strUrlAddress,strdivName)//strUrlAddress代表传递的url地址...

修武县19519252327: asp网站求自动识别手机还是电脑并跳转? -
籍平复方: 只要在首页代码顶部引用call Check_Wap(),用正则判断方便简洁.Sub Check_Wap()dim MoblieUrl,reExp,MbStrMoblieUrl="/3g/index.asp"''手机网站路径Set reExp = New RegExpMbStr="Android|iPhone|UC|Windows Phone|webOS|...

修武县19519252327: 如何让一个判断的asp页面自动返回值 -
籍平复方: 这个简单呀:在url.asp中写上:<% if clng(request.querystring("id"))=1 then response.redirect("页面1") else if clng(request.querystring("id"))=2 then response.redirect("页面2") else if clng(request.querystring("id"))=3 then response.redirect("页面3") else response.redirect("error.asp") end if%> 当然还可以按楼上 vitamincs 的用变量ID的值为页面,也很好的.

修武县19519252327: asp怎样实现响应式页面 自动识别设备分辨率 -
籍平复方: 把下列代码保存在记事本里,然后改名为Style.css存到网页根目录 body{ width: auto; height: auto; } 然后打开你的网页在上面加上一句代码 这样不管你的显示器和浏览器多大,里面的内容显示都是满屏的

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网