Html 如果请求来自某个IP范围,则将用户重定向到页面

Html 如果请求来自某个IP范围,则将用户重定向到页面,html,asp.net-mvc-3,redirect,Html,Asp.net Mvc 3,Redirect,在我的Global.asax.cs文件中,我创建了一个会话启动方法: 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(

在我的Global.asax.cs文件中,我创建了一个会话启动方法:

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.
    }
}
假设
IpIsWithinBoliviaRange()
方法中的代码已经编码并工作,如何重定向请求,以便用户透明地看到我编码的页面

以下是解决方案的快照,您可以更好地了解:

_Layout.cshtml的内容是您所期望的,没有什么不寻常的

在_polialayout.cshtml文件中,我做了一些不同的事情:

@{
    Layout = null;
}

<!DOCTYPE html>

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

    </div>
</body>
</html>
@{
布局=空;
}
玻利维亚页

如果有人从玻利维亚访问该网站,我如何呈现此页面?调用此“视图”的呈现需要执行什么操作?

您应该在
~/Views/\u ViewStart.cshtml中执行此操作

@{
    Layout = Helpers.RedirectHelpers.IpIsWithinBoliviaRange(Request.UserHostAddress) ? "~/Views/Shared/_BoliviaLayout.cshtml" : "~/Views/Shared/_Layout.cshtml";
}

为什么不尝试另一种更“多语言”的方法呢?