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("~/Mobile/");
    }
 }


public static bool isMobileBrowser()
{

    HttpContext context = HttpContext.Current;


    if (context.Request.Browser.IsMobileDevice)
    {
        return true;
    }
    //THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
    if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
    {
        return true;
    }
    //THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
    if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
        context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap"))
    {
        return true;
    }
    //AND FINALLY CHECK THE HTTP_USER_AGENT
    //HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
    if (context.Request.ServerVariables["HTTP_USER_AGENT"] != 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.ServerVariables["HTTP_USER_AGENT"].
                                                ToLower().Contains(s.ToLower()))
            {
                return true;
            }
        }
    }

    return false;
}
araskurdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA Engineer IIICommented:
You will get better results if you use a 3rd party database like this one. You'll need to update it on some schedule.
https://www.nuget.org/packages/WURFL_Official_API
0
ste5anSenior DeveloperCommented:
I prefer using a URL rewrite. Something like

<rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" ignoreCase="true" negate="false" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
        <add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
        <add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
    </conditions>
    <action type="Redirect" url="http://mysite.mobi" appendQueryString="false" redirectType="Found" />
</rule>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
araskurdAuthor Commented:
hi ste5an,

where i put this code ?? please give me instruction or details.

Thanks
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

ste5anSenior DeveloperCommented:
In your web config or application host config.

See Creating Rewrite Rules for the URL Rewrite Module.
0
araskurdAuthor Commented:
this resolve my issue ? do you understood my issue ?
0
Athar SyedCommented:
Your problem is the line

Response.Redirect("~/Mobile/");

Open in new window


When you open the mobile path from the PC it is not redirecting you to the home page. But when you open from a mobile device you are redirected to

http://tendrustikurd.net/Mobile/SamePage.aspx

You should redirect the mobile users to the same page they browsed to

If I go to http://tendrustikurd.net/Login.aspx using a mobile I should be redirected to http://tendrustikurd.net/Mobile/Login.aspx and not http://tendrustikurd.net/Mobile/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.