首页 文章

ASP.NET Windows 身份验证模式,IIS7 和自定义错误页面 - 如何?

提问于
浏览
1

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

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

1 回答

  • 0

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

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

    此外,我有时将以下代码放在 Global 文件的 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)
    

相关问题