araskurd
asked on
i have an issue in Auto detect mobile browser
0
down vote
favorite
i have an issue in Auto detect mobile browser , when from my phone the posts and subjects i have sent via my website to facebook after you you click on the post then it will not enter to the fully of the article in mobile version. for example this link http://tendrustikurd.net/Topic_80_11
if i open it using Computer then its fine also in mobile version its fine too http://tendrustikurd.net/Mobile/Topic_80_11 , but if i send this link to facebook and then i open it via mobile phone then it will not show the post but only show the main page of the website i mean it will redirect you to the home page .. that is big issue for me please i need solution for this...
i used this code:
protected void Page_Load(object sender, EventArgs e)
{
if (isMobileBrowser() == true)
{
Response.Redirect("~/Mobil e/");
}
}
public static bool isMobileBrowser()
{
HttpContext context = HttpContext.Current;
if (context.Request.Browser.I sMobileDev ice)
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVar iables["HT TP_X_WAP_P ROFILE"] != null)
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVar iables["HT TP_ACCEPT" ] != null &&
context.Request.ServerVari ables["HTT P_ACCEPT"] .ToLower() .Contains( "wap"))
{
return true;
}
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVar iables["HT TP_USER_AG ENT"] != null)
{
//Create a list of all mobile types
string[] mobiles =
new[]
{
"midp", "j2me", "avant", "docomo",
"novarra", "palmos", "palmsource",
"240x320", "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 the list created above
//and check if the header contains that text
foreach (string s in mobiles)
{
if (context.Request.ServerVar iables["HT TP_USER_AG ENT"].
ToLower().Contains(s.ToLow er()))
{
return true;
}
}
}
return false;
}
down vote
favorite
i have an issue in Auto detect mobile browser , when from my phone the posts and subjects i have sent via my website to facebook after you you click on the post then it will not enter to the fully of the article in mobile version. for example this link http://tendrustikurd.net/Topic_80_11
if i open it using Computer then its fine also in mobile version its fine too http://tendrustikurd.net/Mobile/Topic_80_11 , but if i send this link to facebook and then i open it via mobile phone then it will not show the post but only show the main page of the website i mean it will redirect you to the home page .. that is big issue for me please i need solution for this...
i used this code:
protected void Page_Load(object sender, EventArgs e)
{
if (isMobileBrowser() == true)
{
Response.Redirect("~/Mobil
}
}
public static bool isMobileBrowser()
{
HttpContext context = HttpContext.Current;
if (context.Request.Browser.I
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVar
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVar
context.Request.ServerVari
{
return true;
}
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVar
{
//Create a list of all mobile types
string[] mobiles =
new[]
{
"midp", "j2me", "avant", "docomo",
"novarra", "palmos", "palmsource",
"240x320", "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 the list created above
//and check if the header contains that text
foreach (string s in mobiles)
{
if (context.Request.ServerVar
ToLower().Contains(s.ToLow
{
return true;
}
}
}
return false;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi ste5an,
where i put this code ?? please give me instruction or details.
Thanks
where i put this code ?? please give me instruction or details.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this resolve my issue ? do you understood my issue ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.nuget.org/packages/WURFL_Official_API