asp.net-mvc – 禁用生产中的Glimpse和glimpse.axd
如何在部署到生产环境时限制对glimpse.axd的访问?
我正在使用自定义的RuntimePolicy来确保在生产中未启用一瞥,但是我想确保用户不能访问axd. 如果我们使用asp.net的授权,那么我明白我可以通过web.config中的位置路径进行保护,但这个选项对我来说是不可用的. 想法? 解决方法
Glimpse提供了几种不同的安全配置机制.
正如你所说,第一个是利用ASP.NET的内置安全功能.为此,在您的web.config中,您可以添加< location>元素,像这样: <location path="glimpse.axd"> <system.web> <authorization> <deny users="*"/> <allow roles="Admin"/> </authorization> </system.web> </location> 而现在只有Admin角色中的用户才能访问Glimpse.axd. 巧合的是,路径不一定是/Glimpse.axd,这只是默认设置.您可以通过对您的web.config进行一些更改,将HttpHandler的位置移动到只有您和您的团队已知的网址: <!-- configure system.webServer and/or system.web depending on your ISS configuration --> <system.webServer> <handlers> <add name="Glimpse" path="unknownLocation.axd" ... /> </handlers> </system.webServer> <system.web> <httpHandlers> <add path="unknownLocation.axd" ... /> </httpHandlers> </system.web> <!-- then just configure Glimpse --> <glimpse defaultRuntimePolicy="On" endpointBaseUri="~/unknownLocation.axd"> 第二种方法是创建一个IRuntimePolicy.只要从其ExecuteOn属性返回RuntimeEvent.ExecuteResource,运行时策略就可以安全地访问资源(通过Glimpse.axd提供).不幸的是,Glimpse旨在忽略对于默认资源(即Glimpse.axd)的请求的IRuntimePolicy.好消息是,您可以更改默认资源.就是这样: >创建或更新类,以便它实现IServiceLocator. < glimpse defaultRuntimePolicy =“On”endpointBaseUri =“?/ Glimpse.axd”serviceLocatorType =“YourNamespace.GlimpseLocator,YourAssembly”> 以下是代码: // Create the ServiceLocator that is referenced in web.config public class GlimpseLocator : IServiceLocator { public T GetInstance<T>() where T : class { if (typeof(T) == typeof(IResource)) return new SecurityResource() as T; return null; } public ICollection<T> GetAllInstances<T>() where T : class { return null; } } //Implementation of new default resource that just redirects public class SecurityResource : IResource { public string Name { get { return "Security"; } } public IEnumerable<ResourceParameterMetadata> Parameters { get { return Enumerable.Empty<ResourceParameterMetadata>(); } } public IResourceResult Execute(IResourceContext context) { return new RedirectResourceResult("/Glimpse.axd?n=glimpse_config"); } } // Your custom runtime policy public class CustomPolicy : IRuntimePolicy { public RuntimeEvent ExecuteOn { get { return RuntimeEvent.ExecuteResource; } } public RuntimePolicy Execute(IRuntimePolicyContext policyContext) { //Perform any logic you like and return RuntimePolicy.On or RuntimePolicy.Off return RuntimePolicy.Off; } } 现在,当用户访问Glimpse.axd时,他们会被重定向到Glimpse.axd?n = glimpse_config,它将显示标准配置页面,或*运行时策略不允许执行名为“glimpse_config”的资源.*消息 – 取决于你的IRuntimePolicy. 所以,像我说的那样,我们优化的用例是第一个,利用ASP.NET的内置安全机制.瞥见并不是绑在那个模型上,你只需跳过几个环来配置自动取款机. 在相关的说明中,我们将在07年7月在Glimpse 2.0,目前正在进行中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 有没有办法每天在.Net Web应用程序中运行一个进
- 更改生成的ASP.Net ID?
- 如何使用MSBuild发布Asp.NET Web应用程序?
- .net – 尝试激活“MyDbContext”时无法解析“DatabaseConf
- asp.net – 什么Jenkins插件可以用于.NET网站部署?
- asp.net-mvc – 用于子操作的MVC OutputCache:它存储在哪里
- asp.net-mvc – 可配置的应用程序洞察检测密钥
- ASP.NET CodeFileBaseClass属性与从System.Web.UI.Page继承
- 为什么GAC和VS引用的程序集不一致?
- asp.net-mvc – IIS站点上的高CPU