<% @ Page Language = "C #" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. xml" %>
<! 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 page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Xmldocument xmldoc = new xmldocument ();
// Create a document Declaration
Xmldeclaration = xmldoc. createxmldeclaration ("1.0", "UTF-8", null );
// Create the root node
Xmlelement rootnode = xmldoc. createelement ("configuration ");
Xmldoc. insertbefore (xmldeclaration, xmldoc. documentelement );
Xmldoc. appendchild (rootnode );
Xmlelement deleettingsnode = xmldoc. createelement ("deleetask ");
Xmlelement connectionstringsnode = xmldoc. createelement ("connectionstrings ");
Xmlelement webbeginnode = xmldoc. createelement ("system. Web ");
Xmldoc. documentelement. prependchild (deleettingsnode );
Rootnode. appendchild (connectionstringsnode );
Rootnode. appendchild (webbeginnode );
Xmlelement webcompilationnode = xmldoc. createelement ("Compilation ");
Webcompilationnode. setattribute ("debug", "true ");
Webbeginnode. prependchild (webcompilationnode );
Xmlelement webauthenticationnode = xmldoc. createelement ("authentication ");
Webauthenticationnode. setattribute ("Mode", "forms ");
Webbeginnode. appendchild (webauthenticationnode );
Xmlelement locationnode = xmldoc. createelement ("location ");
Locationnode. setattribute ("path", "default. aspx ");
Rootnode. appendchild (locationnode );
Xmlelement inwebnode = xmldoc. createelement ("system. Web ");
Locationnode. prependchild (inwebnode );
Xmlelement inauthorizationnode = xmldoc. createelement ("Authorization ");
Inwebnode. prependchild (inauthorizationnode );
Xmlelement inallownode = xmldoc. createelement ("allow ");
Inallownode. setattribute ("Roles", "Administrator ");
Inauthorizationnode. prependchild (inallownode );
Xmlelement indenynode = xmldoc. createelement ("deny ");
Indenynode. setattribute ("users ","*");
Inauthorizationnode. appendchild (indenynode );
Xmldoc. Save (server. mappath ("Web. config "));
Response. Write ("XML file created ");
}
}
</SCRIPT>
No title page