Opening a Configuration File on a Remote Server : Introduction « Configuration « ASP.NET Tutorial






Enable the remote server to accept remote configuration connections by executing the following command from a command prompt:

aspnet_regiis -config+


To disable remove configuration connections, execute the following command:

aspnet_regiis -config-


The aspnet_regiis tool is located in the following path:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Configuration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            Configuration config = WebConfigurationManager.OpenMachineConfiguration(null, txtServer.Text, txtUserName.Text, txtPassword.Text);
            AuthenticationSection section = (AuthenticationSection)config.GetSection("system.web/authentication");
            lblAuthenticationMode.Text = section.Mode.ToString();
        }
        catch (Exception ex)
        {
            lblAuthenticationMode.Text = ex.Message;
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show Config Remote</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblServer"
        Text="Server:"
        AssociatedControlID="txtServer"
        Runat="server" />
    <br />
    <asp:TextBox
        id="txtServer"
        Runat="server" />
    <br /><br />
    <asp:Label
        id="lblUserName"
        Text="User Name:"
        AssociatedControlID="txtUserName"
        Runat="server" />
    <br />
    <asp:TextBox
        id="txtUserName"
        Runat="server" />
    <br /><br />
   <asp:Label
        id="lblPassword"
        Text="Password:"
        AssociatedControlID="txtPassword"
        Runat="server" />
    <br />
     <asp:TextBox
        id="txtPassword"
        TextMode="Password"
        Runat="server" />
    <br /><br />
    <asp:Button
        id="btnSubmit"
        Text="Submit"
        OnClick="btnSubmit_Click"
        Runat="server" />
    <hr />

    Authentication Mode:
    <asp:Label
        id="lblAuthenticationMode"
        Runat="server" />

    </div>
    </form>
</body>
</html>








16.1.Introduction
16.1.1.Overview of Website Configuration
16.1.2.Applying Configuration Settings to a Particular Path
16.1.3.The web.config File
16.1.4.Using Elements
16.1.5.Locking Configuration Settings
16.1.6.Lock the debug attribute, and only the debug attribute, of the element.
16.1.7.Adding Custom Application Settings
16.1.8.Placing Configuration Settings in an External File
16.1.9.Opening a Configuration File on a Remote Server