locked
Redirection per user agent string. RRS feed

  • Question

  • Hi folks,

    I'm looking to redirect older IE clients away from a new SharePoint 2013 installation based on the user agent string. The redirect needs to only affect the home page as we still expect to allow direct URLs to content such as policy documents through.

    The only way I know of to do this is to add a brief piece of server-side code into the home.aspx that assesses the user agent string but I'm wondering if within SharePoint 2013 there's a better way to manage the redirection of specific browser versions? (Specifically any version of IE prior to version 9)

    Cheers,
    Lain

    Wednesday, June 25, 2014 6:10 AM

Answers

  • You do have device channels. They are intended to allow you to provide customised mobile sites for different OSs and/or devices but they operate on the user agent string.

    http://msdn.microsoft.com/en-us/library/office/jj862343(v=office.15).aspx

    You could, for a starter, create a device channel that takes your Vista users to a page saying 'sorry, not going to work' and possibly get the redirection code to work that way.

    I'm not sure it'll work as you'd still be trying to render a master page but i'd say it's worth examining.

    Wednesday, June 25, 2014 10:08 AM
  • Device Channels are for Publishing sites, so this possibly wouldn't likely work unless that is what you are using.  If you are indeed wanting to do this without using code fragments then perhaps a suggestion is to use the URL Rewrite moduel in IIS, and create a browser rule that issues a bit of redirection javascript to the client based on the user agent.  There's an example to get you started here which I have never tried, but it might give you the basis to craft something simply.

    http://blogs.msdn.com/b/robert_mcmurray/archive/2012/02/03/using-url-rewrite-to-insert-different-scripts-based-on-browser-type.aspx

     

    Regards John Timney http://www.johntimney.com

    • Marked as answer by Rebecca Tu Monday, July 7, 2014 8:10 AM
    Wednesday, June 25, 2014 4:16 PM

All replies

  • Best way is 

    Create some content editor webparts on home page

    Add redirection script to all the webparts. 

    Now using audience feature add users to audience

    assign each audience to each webpart

    so users will be redirected to site based on webpart audience is part of

    http://office.microsoft.com/en-in/sharepoint-server-help/target-content-to-specific-audiences-HA010169053.aspx

    http://technet.microsoft.com/en-in/library/cc261958%28v=office.14%29.aspx


    If this helped you resolve your issue, please mark it Answered

    Wednesday, June 25, 2014 6:24 AM
  • Hi Inderjeet,

    Thanks, but I'm not sure how that's going to help as I'm not looking to customise web parts. Perhaps I should explain the scenario a little better.

    We have an old intranet environment and now a new intranet environment. The new intranet is based upon SharePoint 2013. These two environments are on separate servers (I'm sure you already assumed that).

    We need to keep both intranets running side-by-side in the interim until we have finished migrating the remainder of our desktop fleet. Without going into the details, we have a bunch of non-upgradable Vista machines that cannot be moved to IE9, which is required to view the new intranet.

    So, the behaviour we need to establish is that when a user on a Windows Vista machine with IE7 and prior accesses the new intranet home page, it needs to be sent a redirect to the URL of the old intranet server.

    The new intranet has already been designed and there's no capacity to change that design.

    Cheers,
    Lain

    Wednesday, June 25, 2014 6:44 AM
  • Below script should help you 

    http://stackoverflow.com/questions/10869708/how-do-i-redirect-my-client-to-a-different-page-according-to-their-browser

     <script language="JavaScript" type="text/JavaScript">
        if(navigator.appName == "Mozilla")
        {
         window.location = "ff/index.html"
        }
         if(navigator.appName == "Microsoft Internet Explorer")
        {
         window.location = "ie/index.html"
        }
         if(navigator.appName == "Google Chrome")
        {
         window.location = "ch/index.html"
        }
         if(navigator.appName == "Safari")
        {
         window.location = "sa/index.html"
        }
         if(navigator.appName == "Google Chrome")
        {
         window.location = "ch/index.html"
        }
         window.location == "un/index.html"
        </script>

    Or

    var redirects = { "Mozilla": "ff", "Microsoft Internet Explorer": "ie", "Google Chrome": "ch", "Safari": "sa", "Google Chrome": "ch" };

    window.location = (redirects[navigator.appName] || "un") + "/index.html";

    For IE

    <!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->
    <![if !IE]><p>You are not using Internet Explorer.</p><![endif]>
    
    <!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]-->
    <!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->
    
    <!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]-->
    <!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
    <!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
    <!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->
    
    <!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
    <![if false]>You are using a <em>downlevel</em> browser.<![endif]>
    
    <!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]-->


    If this helped you resolve your issue, please mark it Answered

    Wednesday, June 25, 2014 6:50 AM
  • Thanks Inderjeet,

    This coding isn't the issue - I can manage that easily, and I'd prefer to keep things more efficient in having the redirection server-side rather than feeding up the entire page only to have the client process a script and redirect.

    I was just wondering if there wasn't a mechanic within SharePoint itself I could have leveraged without having to change Home.aspx (or to serve up the whole page). If there's not, then I'll stick to my original approach.

    Cheers,
    Lain

    Wednesday, June 25, 2014 9:26 AM
  • You do have device channels. They are intended to allow you to provide customised mobile sites for different OSs and/or devices but they operate on the user agent string.

    http://msdn.microsoft.com/en-us/library/office/jj862343(v=office.15).aspx

    You could, for a starter, create a device channel that takes your Vista users to a page saying 'sorry, not going to work' and possibly get the redirection code to work that way.

    I'm not sure it'll work as you'd still be trying to render a master page but i'd say it's worth examining.

    Wednesday, June 25, 2014 10:08 AM
  • Device Channels are for Publishing sites, so this possibly wouldn't likely work unless that is what you are using.  If you are indeed wanting to do this without using code fragments then perhaps a suggestion is to use the URL Rewrite moduel in IIS, and create a browser rule that issues a bit of redirection javascript to the client based on the user agent.  There's an example to get you started here which I have never tried, but it might give you the basis to craft something simply.

    http://blogs.msdn.com/b/robert_mcmurray/archive/2012/02/03/using-url-rewrite-to-insert-different-scripts-based-on-browser-type.aspx

     

    Regards John Timney http://www.johntimney.com

    • Marked as answer by Rebecca Tu Monday, July 7, 2014 8:10 AM
    Wednesday, June 25, 2014 4:16 PM
  • Thanks for the feedback, John and Alex.

    It sounds like there's a few options but none that are necessarily any better than editing the Home.aspx side directly using the HttpRequest and HttpResponse classes to send back a straight 302 (under the appropriate conditions).

    That being the case, while I'm glad I asked for alternatives, I think I'll stick with my initial approach.

    Cheers,
    Lain

    Wednesday, June 25, 2014 11:34 PM