配置自定义授权使用ELMAH [英] Configuring custom authorization with ELMAH

查看:374
本文介绍了配置自定义授权使用ELMAH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何配置ELMAH为某些人只显示不默认的ASP.NET授权角色的经理吗?

How can I configure ELMAH to display only for certain people without default ASP.NET authorization roles manager?

我(以及许多其他人,我认为)用我自己的授权逻辑,并建立从零我的项目,而无需使用提供的模板。我想记录错误,但它似乎是不可能的配置ELMAH(以某种方式重写的功能),使之与其他一些授权工作,甚至使它只对特定IP地址的工作。

I (as well as many others, I think) use my own authorization logic and build my projects from zero without using provided templates. I want to log errors but it seems that it is impossible to configure ELMAH (somehow override functionality) to make it work with some other authorization or even to make it work only for particular IP addresses.

由于我将有机会获得的web.config 我试图以不默认显示ELMAH改变这些值。

Since I will have access to web.config I tried to change these values in order to NOT display elmah by default.

<add key="elmah.mvc.disableHandler" value="false" />
<add key="elmah.mvc.disableHandleErrorFilter" value="false" />
<add key="elmah.mvc.requiresAuthentication" value="false" />

而当我想查看错误切换他们从真正,看到的错误,然后切换回来。但似乎当我改变这些值的所有记录将被清除。

And when I want to view errors switch them from true to false and see errors, then switch back. But it seems that when I change these values all logs are erased.

我该怎么办?

推荐答案

我觉得最简单的办法是做一些小的改动你的自定义授权因此ELMAH授权将工作。

I think the easiest approach would be to make some minor alterations to your custom authorization so the ELMAH authorization will work.

选项1::设置在登录时FormsAuthentication饼干。通过这种方式,在web.config中的允许用户=用户名应该工作。成功登录后,你可以设置cookie的
<一href=\"http://msdn.microsoft.com/en-us/library/twk5762b.aspx\">FormsAuthentication.SetAuthCookie(theUsername,真)。

Option 1: Set the FormsAuthentication cookie on login. This way, in the web.config the allow users="username" should work. On successful login you can set the cookie with FormsAuthentication.SetAuthCookie(theUsername, true).

该ELMAH授权看起来是这样的:

The ELMAH authorization would look something like:

<location path="elmah.axd" inheritInChildApplications="false">
    <system.web>
       <authorization>   
         <allow users="theUserName" />
         <deny users="*" />
       </authorization>
    </system.web>
  ...other config settings
</location>

选项2:如果您使用的是把用户分为角色,您可以覆盖默认的角色提供使用你就该好好角色的功能。这种方式是一个涉及多一点,但然后让你在web.config中,这是非常好的用于保护之类的静态文件(.PDF等)交付利用基础角色的认证。如果有兴趣,我可以添加code这一点。

Option 2: If you are using putting users into roles, you can override the default role provider to use the function you made to get roles. This way is a little more involved but then lets you harness role-basing authentication in the web.config, which is really nice for securing things like static file (.pdf etc) delivery. I can add code for this if interested.

这篇关于配置自定义授权使用ELMAH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆