I am putting a redirect in my master template to see if the incoming user is using a mobile device, and if so redirect to the altTemplate Mobile. How can I get this to work correctly? I need to redirect to page.aspx?altTemplate=mobile, I can get it all to work except appending the page.aspx. I am using:
<script runat="server" language="c#">
public void Page_Load(Object sender, EventArgs e) { if (Request.Browser["IsMobileDevice"] == "true" ) { Response.Redirect("?alttemplate=mobile"); } }
Redirecting for mobile applications using altTemplate
I am putting a redirect in my master template to see if the incoming user is using a mobile device, and if so redirect to the altTemplate Mobile. How can I get this to work correctly? I need to redirect to page.aspx?altTemplate=mobile, I can get it all to work except appending the page.aspx. I am using:
<script runat="server" language="c#">
public void Page_Load(Object sender, EventArgs e)
{
if (Request.Browser["IsMobileDevice"] == "true" )
{
Response.Redirect("?alttemplate=mobile");
}
}
</script>
Get the current page from the 'ServerVariables' collection using
or use
to get the url of the current page
Hope this helps.
Regards,
/Dirk
That did not seem to work, I used the following and was given an error...
<script runat="server" language="c#">
public void Page_Load(Object sender, EventArgs e)
{
if (Request.Browser["IsMobileDevice"] == "true" )
{
Response.Redirect(Request.ServerVariables("URL")&"?alttemplate=mobile");
}
}
</script>
It is telling me that it is a property being used as a method...
Evan, small mistake as c# indexer uses [] instead of (). And you'll have to replace '&' with '+'
Cheers,
Dirk
Ahh, perfect thanks..
is working on a reply...