Skip to content

Instantly share code, notes, and snippets.

@kiyokura
Created December 3, 2013 13:32
Show Gist options
  • Save kiyokura/7769157 to your computer and use it in GitHub Desktop.
Save kiyokura/7769157 to your computer and use it in GitHub Desktop.
GlimpseSecurityPolicy.csでIPアドレスでポリシー制御を行うサンプル
using Glimpse.AspNet.Extensions;
using Glimpse.Core.Extensibility;
using System.Collections.Generic;
namespace DapperSampleWeb
{
public class GlimpseSecurityPolicy:IRuntimePolicy
{
public RuntimePolicy Execute(IRuntimePolicyContext policyContext)
{
// 許可IPアドレスリスト(実際はWebConfigとかから読んでキャッシュとかする)
var allowList = new List<string>()
{
"127.0.0.1",
"172.16.1.10"
};
var httpContext = policyContext.GetHttpContext(); // CurrentのHttpContextを取得
if (allowList.Contains(httpContext.Request.ServerVariables["REMOTE_ADDR"]))
{
return RuntimePolicy.On;
}
else
{
return RuntimePolicy.Off;
}
}
public RuntimeEvent ExecuteOn
{
get { return RuntimeEvent.EndRequest; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment