c# - Url Redirection based on the Device -
what need regarding mobile , app redirection if person enters site mobile device?
1) if device uses ios (except ipad) suggest user should download mobile app. clicking on link user redirected appstore. if user clicks on “skip app download” forward user m.example.com
2) if device uses android, suggest user should download mobile app. clicking on link user redirected google play. if user clicks on “skip app download” forward user m.example.com
3) if user enters through mobile device, forward them mobile site m.abc.com.
4) if device other above: forward m.example.com. links should opened in m.example.com format. links should converted to:
a. if person visits www.example.com/viewvacancy.aspx?id=66880 link should converted http://m.example.com/vacancy.aspx?name=66880
b. if person visits other page abc.com mobile. should redirected http://m.example.com
in global.asax
add following code:
protected void application_acquirerequeststate(object sender, eventargs e) { httpcontext context = httpcontext.current; if (context.request.browser.ismobiledevice) { // logic } if (context.request.servervariables["http_user_agent"] != null) { //create list of mobile types string[] mobiles = new[] { "midp", "j2me", "avant", "docomo", "novarra", "palmos", "palmsource", "240×320", "opwv", "chtml", "pda", "windows ce", "mmp/", "blackberry", "mib/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up.b", "audio", "sie-", "sec-", "samsung", "htc", "mot-", "mitsu", "sagem", "sony" , "alcatel", "lg", "eric", "vx", "nec", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "dddi", "moto", "iphone" }; //loop through each item in list created above //and check if header contains text foreach (string s in mobiles) { if (context.request.servervariables["http_user_agent"]. tolower().contains(s.tolower())) { //your logic } } } }
hope may helpful.,
Comments
Post a Comment