查看 elmah 日志而不创建角色/用户身份验证

发布于 2025-01-08 09:53:34 字数 190 浏览 0 评论 0原文

我开始使用 ELMAH,我认为它很棒。我在线阅读了一些文档,但现在我的应用程序没有角色/用户授权设置。

我希望能够通过访问 /elmah.axd 来读取生产上的错误日志,但我不想只向所有人开放它,elmah 是否有任何功能允许我创建密码(在 web.xml 中)。配置)并通过查询字符串传递它?模仿“安全”RSS 提要。或者类似的东西当然......

I started using ELMAH and I think its great. I read some documentation online but right now my app doesn't have roles/user authorization setup.

I would like to be able to read the error logs on production by accessing /elmah.axd but I don't want to just open it up to everyone, does elmah have any functionality that would allow me to create a password (in web.config) and pass it via querystring? Mimicking a "secure" RSS feed. Or something similar ofcourse....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅冕 2025-01-15 09:53:34

但现在我的应用没有角色/用户授权设置

实际上配置表单身份验证并不难:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880">
    <credentials passwordFormat="Clear">
      <user name="admin" password="secret" />
    </credentials>
  </forms>
</authentication>

然后保护elmah.axd

<location path="elmah.axd">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
</location>

最后你可以拥有一个AccountController:

public class AccountController : Controller
{
    public ActionResult LogOn()
    {
        return View();
    }

    [HttpPost]
    public ActionResult LogOn(string username, string password)
    {
        if (FormsAuthentication.Authenticate(username, password))
        {
            FormsAuthentication.SetAuthCookie(username, false);
            return Redirect("~/elmah.axd");
        }
        else
        {
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
        }
        return View();
    }
}

和一个 LogOn.cshtml 视图:

@Html.ValidationSummary(false)

@using (Html.BeginForm()) 
{
    <div>
        @Html.Label("username")
        @Html.TextBox("username")
    </div>
    <div>
        @Html.Label("password")
        @Html.Password("password")
    </div>
    <p>
        <input type="submit" value="Log On" />
    </p>
}

现在,当匿名用户尝试访问 /elmah.axd 时,他将看到登录屏幕,需要在其中进行身份验证命令访问它。用户名/密码组合位于 web.config 中。我在本示例中使用了 passwordFormat="Clear",但您也可以对密码进行 SHA1 或 MD5 处理。


当然,如果您不想配置身份验证,您也可以配置 elmah 将日志信息存储在 XML 文件或 SQL 数据库中,然后从您的公开网站完全禁用 elmah.axd 处理程序。然后创建另一个 ASP.NET 站点,只有您可以使用指向相同日志源的相同 elmah 配置访问该站点,然后只需导航到您的私有站点的 /elmah.axd 处理程序即可读取公共站点的日志。

but right now my app doesn't have roles/user authorization setup

Actually it's not that hard to configure forms authentication:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880">
    <credentials passwordFormat="Clear">
      <user name="admin" password="secret" />
    </credentials>
  </forms>
</authentication>

and then protect elmah.axd:

<location path="elmah.axd">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
</location>

and finally you could have an AccountController:

public class AccountController : Controller
{
    public ActionResult LogOn()
    {
        return View();
    }

    [HttpPost]
    public ActionResult LogOn(string username, string password)
    {
        if (FormsAuthentication.Authenticate(username, password))
        {
            FormsAuthentication.SetAuthCookie(username, false);
            return Redirect("~/elmah.axd");
        }
        else
        {
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
        }
        return View();
    }
}

and a LogOn.cshtml view:

@Html.ValidationSummary(false)

@using (Html.BeginForm()) 
{
    <div>
        @Html.Label("username")
        @Html.TextBox("username")
    </div>
    <div>
        @Html.Label("password")
        @Html.Password("password")
    </div>
    <p>
        <input type="submit" value="Log On" />
    </p>
}

Now when an anonymous user tries to access /elmah.axd he will be presented with the logon screen where he needs to authenticate in order to access it. The username/password combination is in web.config. I have used passwordFormat="Clear" in this example but you could also SHA1 or MD5 the password.


Of course if you don't want to configure authentication you could also configure elmah to store logging information in a XML file or SQL database and then completely disable the elmah.axd handler from your publicly facing website. Then create another ASP.NET site which only you would have access to with the same elmah configuration pointing to the same log source and simply navigate to the /elmah.axd handler of your private site to read the logs of your public site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文