I just realized you also wanted the defaultRedirect value.
Here's the modified code :
---------------------------------------
<%@ Page Language="VB" %>
<%@ Import Namespace="Syst em.Web.Configur ation" %>
<%@ Import Namespace="Syst em.Configuratio n" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
' Set the root path of the Web application that contains the Web.config file that you want to access.
Dim configuration As System.Configur ation.Configura tion = WebConfiguratio nManager.OpenWe bConfiguration( "/YourAppName")
' Get the section.
Dim customErrorsSec tion As CustomErrorsSec tion = CType(configura tion.GetSection ("system.web/customErrors"), CustomErrorsSec tion)
' Read the <customErrorsse ction mode.
Dim currentMode As CustomErrorsMod e = customErrorsSec tion.Mode
Dim currentDefaultR edirect As String = customErrorsSec tion.defaultRed irect
' Display the <customErrorsan d defaultRedirect page information.
ConfigId.Text = "customErro rs is: " & currentMode.ToS tring() & ", and the defaultRedirect page is : " & currentDefaultR edirect
End Sub
</script>
<html >
<head>
<title>Read customErrors Configuration Setting</title>
</head>
<body>
<p>
This page displays the <b>values</bof the <b>customErro rs and defaultRedirect </bsections of web.config.
</p>
<h3>Values:</h3>
<p>
<asp:Label ID="ConfigId" BackColor="#dcd cdc" 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" <no***********@ nowhere.comwrot e in message news:ua******** ******@TK2MSFTN GP03.phx.gbl...
re:
Hi. Is it programatically possible in VB.NET to read the contents of web.config's <customErrorsel ement?
Sure it's possible.
See it working at :
http://asp.net.do/test/readCustomErrors.aspx
Here's the source for that sample I wrote :
readCustomError s.aspx:
-----------------------------------
<%@ Page Language="VB" %>
<%@ Import Namespace="Syst em.Web.Configur ation" %>
<%@ Import Namespace="Syst em.Configuratio n" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
' Set the root path of the Web application that contains the Web.config file that you want to access.
Dim configuration As System.Configur ation.Configura tion = WebConfiguratio nManager.OpenWe bConfiguration( "/test")
' Get the section.
Dim customErrorsSec tion As CustomErrorsSec tion = CType(configura tion.GetSection ("system.web/customErrors"), CustomErrorsSec tion)
' Read the <customErrorsse ction mode.
Dim currentMode As CustomErrorsMod e = customErrorsSec tion.Mode
' Display the <customErrorsin formation.
ConfigId.Text = currentMode.ToS tring()
End Sub
</script>
<html >
<head>
<title>Read customErrors Configuration Setting</title>
</head>
<body>
<p>
This page displays the <b>value</bof the <b>customErrors </bsection of web.config.
</p>
<h3>Value:</h3>
<p>
<asp:Label ID="ConfigId" BackColor="#dcd cdc" 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/
=============== =============== =====
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message news:5B******** *************** ***********@mic rosoft.com...
Hi. Is it programatically possible in VB.NET to read the contents of
web.config's <customErrorsel ement? I looked at using
ConfigurationSe ttings.AppSetti ngs, but that doesn't work.
I need to read the value of redirect from the error statusCode 404. My
web.config looks like this:
<customErrors mode="RemoteOnl y" defaultRedirect ="Error.aspx ">
<error statusCode="404 " redirect="Error 404.aspx" />
</customErrors>
Thanks!