0

In my Global.asax.cs file, I created a Session_Start method:

protected void Session_Start(object sender, EventArgs e)
{
    //Get the incoming user's IP address.
    var ip = HttpContext.Current.Request.UserHostAddress;

    if (Helpers.RedirectHelpers.IpIsWithinBoliviaRange(ip))
    {
        //Render the bolivia page.
    }
    else
    {
        //Render the regular layout page.
    }
}

Assuming the code in the IpIsWithinBoliviaRange() method is already coded and working, how do I redirect the request so the user transparently sees a page I coded up?

Here is a snapshot of the solution so you can get a better picture:

enter image description here

The contents of _Layout.cshtml is what you would expect, nothing out of the ordinary.

On the _BoliviaLayout.cshtml file I've done something different:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>BOLIVIA PAGE</title>
</head>
<body>
    <div>

    </div>
</body>
</html>

How can I render this page if someone coming in from Bolivia visits the site? What do I need to do to invoke the rendering of this "view"?

Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257
  • Why not try a different more 'multi language' approach? http://stackoverflow.com/questions/6671992/how-do-you-handle-static-list-internationalization-in-asp-net-mvc – Adam Tuliper Mar 08 '12 at 18:22

1 Answers1

1

You should do this in the ~/Views/_ViewStart.cshtml

@{
    Layout = Helpers.RedirectHelpers.IpIsWithinBoliviaRange(Request.UserHostAddress) ? "~/Views/Shared/_BoliviaLayout.cshtml" : "~/Views/Shared/_Layout.cshtml";
}
amit_g
  • 30,880
  • 8
  • 61
  • 118