I just realized you also wanted the defaultRedirect value.
Here's the modified code :
---------------------------------------
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Set the root path of the Web application that contains the Web.config file that you want to access.
Dim configuration As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/YourAppName")
' Get the section.
Dim customErrorsSection As CustomErrorsSection = CType(configuration.GetSection("system.web/customErrors"), CustomErrorsSection)
' Read the <customErrors> section mode.
Dim currentMode As CustomErrorsMode = customErrorsSection.Mode
Dim currentDefaultRedirect As String = customErrorsSection.defaultRedirect
' Display the <customErrors> and defaultRedirect page information.
ConfigId.Text = "customErrors is: " & currentMode.ToString() & ", and the defaultRedirect page is : " & currentDefaultRedirect
End Sub
</script>
<html >
<head>
<title>Read customErrors Configuration Setting</title>
</head>
<body>
<p>
This page displays the <b>values</b> of the <b>customErrors and defaultRedirect</b> sections of web.config.
</p>
<h3>Values:</h3>
<p>
<asp:Label ID="ConfigId" BackColor="#dcdcdc" BorderWidth="1" runat="Server" /></p>
</body>
</html>
-------------
The modified sample is at :
http://asp.net.do/test/readCustomErrors.aspx
Juan T. Llibre, asp.net MVP
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
===================================
Juan T. Llibre said:
Hi. Is it programatically possible in VB.NET to read the contents of web.config's <customErrors> element?
Sure it's possible.
See it working at :
http://asp.net.do/test/readCustomErrors.aspx
Here's the source for that sample I wrote :
readCustomErrors.aspx:
-----------------------------------
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Set the root path of the Web application that contains the Web.config file that you want to access.
Dim configuration As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/test")
' Get the section.
Dim customErrorsSection As CustomErrorsSection = CType(configuration.GetSection("system.web/customErrors"), CustomErrorsSection)
' Read the <customErrors> section mode.
Dim currentMode As CustomErrorsMode = customErrorsSection.Mode
' Display the <customErrors> information.
ConfigId.Text = currentMode.ToString()
End Sub
</script>
<html >
<head>
<title>Read customErrors Configuration Setting</title>
</head>
<body>
<p>
This page displays the <b>value</b> of the <b>customErrors</b> section of web.config.
</p>
<h3>Value:</h3>
<p>
<asp:Label ID="ConfigId" BackColor="#dcdcdc" BorderWidth="1" runat="Server" /></p>
</body>
</html>
-----------
Enjoy!
Juan T. Llibre, asp.net MVP
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
===================================