【问题标题】:ASP.NET Windows Authentication Mode, IIS7 and custom error pages - how?ASP.NET Windows 身份验证模式、IIS7 和自定义错误页面 - 如何?
【发布时间】:2011-11-25 16:06:13
【问题描述】:

我有很多用户。如果他们不是特定角色,我不希望他们访问该站点。这很简单,使用股票 .NET 成员资格/角色提供程序,将身份验证模式设置为 Windows 并设置一些访问规则并在请求结束时拦截,以重定向到自定义 401 错误页面 - 使用 Cassini。

向前推进 IIS7 和集成管道,当使用此版本的 IIS 和这种操作模式将我的站点部署到 Web 服务器时,这怎么可能?我应该恢复到经典应用程序池,还是违背了对管道中的请求进行更多控制的目的。

【问题讨论】:

  • 您现在有什么问题?成员资格和角色提供程序在 IIS7 中仍然有效。
  • 是的。我的问题是,尽管似乎提供了整个 Http 错误(例如 401 到 500)以及设置自定义错误的能力。实际上,提供一个非静态、母版页驱动的错误页面(适用于 Cassini)被证明似乎“不可能”使用 IIS7 和集成模式进行配置。
  • 编辑以传达没有什么是不可能的

标签: c# asp.net iis-7


【解决方案1】:

我知道这是非常基本的,但你试过了吗?这在 Web.config 文件中。

<customErrors mode="On" defaultRedirect="Error.aspx">
    </customErrors>

另外,我有时将以下代码放在全局文件的 Application_Error 事件中以记录异常:

    ' Fires when an error occurs
    ' Code that runs when an unhandled error occurs

    Dim ErrorDescription As String = Server.GetLastError.ToString

    ' Log the Error to Event Log
    'Creation of event log if it does not exist  
    Dim EventLogName As String
    EventLogName = ConfigurationManager.AppSettings("ApplicationLog").ToString()

    If (Not EventLog.SourceExists(EventLogName)) Then
      EventLog.CreateEventSource(EventLogName, EventLogName)
    End If

    ' Inserting into event log
    Dim Log As New EventLog()
    Log.Source = EventLogName
    Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)

【讨论】:

  • 不幸的是,这不起作用。 401.2 和 401.3 错误的自定义错误超出了 ASP.NET 处理的范围。据我了解,在 ASP.NET 处理无效请求之前,它们由 IIS7 处理,您必须像时髦的鸡一样跳舞才能显示优雅的错误消息。
猜你喜欢
  • 1970-01-01
  • 2011-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-26
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
相关资源
最近更新 更多