views:

18

answers:

1

Is it possible to configure web.config to authorize a page to be only read locally (similar in concept to the RemoteOnly feature for error messages).

A: 

You can check this on the Page that you wish to. Here is an example code that I write and check if the user is local or not.

override protected void OnInit(EventArgs e)
{
    if (!IsUserLocal())
    {
        Response.Redirect("~/");
        return;
    }

    base.OnInit(e);
}

public bool IsUserLocal()
{
    string userHostAddress = Request.ServerVariables["REMOTE_HOST"].ToString();

    if (string.IsNullOrEmpty(userHostAddress))
    {
        return false;
    }
    return (((userHostAddress == "127.0.0.1") || (userHostAddress == "::1")) || (userHostAddress == LocalAddress()));
}


public string LocalAddress()
{
    IServiceProvider provider = (IServiceProvider)HttpContext.Current;
    HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));

    return wr.GetLocalAddress();
}
Aristos