Created
December 3, 2013 13:32
-
-
Save kiyokura/7769157 to your computer and use it in GitHub Desktop.
GlimpseSecurityPolicy.csでIPアドレスでポリシー制御を行うサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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