.NET Time Picker Updates

February 18th, 2009 Michael Bell 10 comments

I released some updates night before last. One new function is the ability to make the picker work as a clock in nature, rather than… well.. a picker!

  • EnableClock is the new property that allows real time clock ticking action.
  • IsReadOnly has been renamed to ReadOnly (don’t know what I was thinking at the time), and it’s functionality has been imporved in that the numbers in the clock are not even selectable from the user interface when this option is set to true.
  • The control now will return seconds, when AllowSecondEditing is set to true.

That and I updated the time picker example page to reflect these new changes: .NET Time Picker Example Page

Categories: ASP.NET, c# Tags:

Configuring Microsoft AJAX to work in SharePoint 2007, MOSS

February 6th, 2009 Michael Bell 3 comments

I had the pleasure of recently converting a couple of webparts & controls to use Microsoft AJAX rather than AJAXPro.net. On top of all of my control changes, I had to do quite a few config file changes to SharePoint to ge tit to work correctly. Now, the instructions for this are out there on Microsofts site, and kudos to them for providing that. What they didn’t include, is sample code to implement these changes through managed code to your SharePoint farm. So that’s what this example does:

public override void SetConfigModifications(SPWebApplication WebApp, string Owner)
{
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@path='*.asmx']",
"configuration/system.web/httpHandlers", @"<add verb='*' path='*.asmx' validate='false'
type='System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@path='*_AppService.axd']",
"configuration/system.web/httpHandlers", @"<add verb='*' path='*_AppService.axd' validate='false'
type='System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@path='ScriptResource.axd']",
"configuration/system.web/httpHandlers", @"<add verb='GET,HEAD' path='ScriptResource.axd'
type='System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' validate='false'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // AJAX HttpModule
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='ScriptModule'][@type='System.Web.Handlers.ScriptModule, " +
"System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35']",
"configuration/system.web/httpModules", @"<add name='ScriptModule' type='System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // Microsoft AJAX Tie-In
#region Sections and Groups
// SectionGroup for system.web.extensions
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("sectionGroup[@name='system.web.extensions']",
"configuration/configSections", @"<sectionGroup name='system.web.extensions'
type='System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // SectionGroup for scripting
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("sectionGroup[@name='scripting']",
"configuration/configSections/sectionGroup[@name='system.web.extensions']", @"<sectionGroup name='scripting'
type='System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("section[@name='scriptResourceHandler']",
"configuration/configSections/sectionGroup[@name='system.web.extensions']/sectionGroup[@name='scripting']",
@"<section name='scriptResourceHandler'
type='System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' requirePermission='false' allowDefinition='MachineToApplication'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("sectionGroup[@name='webServices']",
"configuration/configSections/sectionGroup[@name='system.web.extensions']/sectionGroup[@name='scripting']",
@"<sectionGroup name='webServices'
type='System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("section[@name='jsonSerialization']",
"configuration/configSections/sectionGroup[@name='system.web.extensions']/sectionGroup[@name='scripting']/" +
"sectionGroup[@name='webServices']", @"<section name='jsonSerialization'
type='System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' requirePermission='false' allowDefinition='Everywhere' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("section[@name='profileService']",
"configuration/configSections/sectionGroup[@name='system.web.extensions']/sectionGroup[@name='scripting']/" +
"sectionGroup[@name='webServices']", @"<section name='profileService'
type='System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral,  PublicKeyToken=31bf3856ad364e35' requirePermission='false' allowDefinition='MachineToApplication' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("section[@name='authenticationService']",
"configuration/configSections/sectionGroup[@name='system.web.extensions']/sectionGroup[@name='scripting']/" +
"sectionGroup[@name='webServices']", @"<section name='authenticationService'
type='System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' requirePermission='false' allowDefinition='MachineToApplication' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));
#endregion

 // AJAX Assembly
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification(
"add[@assembly='System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35']",
"configuration/system.web/compilation/assemblies",
"<add assembly='System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // Pages Section
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("controls",
"configuration/system.web/pages", "controls",
SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 // Pages entry for AJAX Assembly
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification(
"add[@tagPrefix='asp'][@assembly='System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35']",
"configuration/system.web/pages/controls",
"<add tagPrefix='asp' namespace='System.Web.UI' assembly='System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // AJAX SafeControls Entry
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification(
"SafeControl[@Assembly='System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35']",
"configuration/SharePoint/SafeControls",
"<SafeControl Assembly='System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Namespace='System.Web.UI' TypeName='*' Safe='True' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // AJAX System.Web.Extensions Section
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("system.web.extensions",
"configuration", "system.web.extensions", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("scripting",
"configuration/system.web.extensions", "scripting", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("webServices",
"configuration/system.web.extensions/scripting", "webServices", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 // AJAX System.webServer Section
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("system.webServer",
"configuration", "system.webServer", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("validation[@validateIntegratedModeConfiguration='false']",
"configuration/system.webServer", "<validation validateIntegratedModeConfiguration='false'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // AJAX System.webServer Modules Section
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("modules",
"configuration/system.webServer", "modules", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='ScriptModule'][@preCondition='integratedMode']",
"configuration/system.webServer/modules", @"<add name='ScriptModule' preCondition='integratedMode'
type='System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // Web Services to system.web
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("webServices",
"configuration/system.web", "webServices", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("protocols",
"configuration/system.web/webServices", "protocols", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='HttpGet']",
"configuration/system.web/webServices/protocols", @"<add name='HttpGet' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='HttpPost']",
"configuration/system.web/webServices/protocols", @"<add name='HttpPost' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 // AJAX System.webServer Handlers Section
WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("handlers",
"configuration/system.webServer", "handlers", SPWebConfigModification.SPWebConfigModificationType.EnsureSection, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("remove[@name='WebServiceHandlerFactory-Integrated']",
"configuration/system.webServer/handlers", @"<remove name='WebServiceHandlerFactory-Integrated' />",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='ScriptHandlerFactory']",
"configuration/system.webServer/handlers", @"<add name='ScriptHandlerFactory' verb='*' path='*.asmx'
preCondition='integratedMode'
type='System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='ScriptHandlerFactoryAppServices']",
"configuration/system.webServer/handlers", @"<add name='ScriptHandlerFactoryAppServices' verb='*'
path='*_AppService.axd' preCondition='integratedMode'
type='System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

 WebApp.WebConfigModifications.Add(WebConfigManager.CreateModification("add[@name='ScriptResource'][@preCondition='integratedMode']",
"configuration/system.webServer/handlers", @"<add name='ScriptResource' preCondition='integratedMode'
verb='GET,HEAD' path='ScriptResource.axd'
type='System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'/>",
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Owner));

WebApp.Update();
WebApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
Categories: AJAX, ASP.NET, MOSS, SharePoint 2007, c# Tags:

Creating an IIS Site through managed code (C#, .NET)

January 23rd, 2009 Michael Bell 3 comments

Another task I had in the past along with creating the DNS entries via managed code, was creating a new site in IIS. I had to nip various code from various places, but when I got done, it all worked nicely together. You will notice by the try catch block, that again, I was executing this chunk of code from a web based application. Needless to say, chances are you won’t have the permissions to do this unless you do. This code works on IIS 6.0 with Windows 2003 Server Std Edition . I’d imagine it’s more IIS specific than OS specific, but this is the only version of Windows I’ve tested it with.

public static string CreateWebSite(string NewSiteIP, string webSiteName, string pathToRoot, string DomainName)
{
int siteID = 1;
string sSiteID = “”;
try
{

CreatePhysicalDirectory(pathToRoot, webSiteName);

ManagementScope _scope = new ManagementScope(@”\\WINDOWS\root\MicrosoftIISV2″, null);
_scope.Connect();

ManagementObject oW3SVC = new ManagementObject(_scope, new ManagementPath(@”IIsWebService=’W3SVC’”), null);
DirectoryEntry root = new DirectoryEntry(”IIS://WINDOWS/W3SVC”);

#region get a good site id
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == “IIsWebServer”)
{
int ID = Convert.ToInt32(e.Name);
if (ID >= siteID)
siteID = ID + 1;
}
}
#endregion

ManagementScope mScope = null;
ManagementPath mPath = new ManagementPath();
mPath.ClassName = “ServerBinding”;
mPath.NamespacePath = “root\\MicrosoftIISv2″;
mScope = new ManagementScope(mPath);
mScope.Path.Server = “WINDOWS”;

#region Create the new Site
ManagementBaseObject[] serverBindings = new ManagementBaseObject[2];
serverBindings[0] = CreateServerBinding(DomainName, NewSiteIP, “80″);
serverBindings[1] = CreateServerBinding(”www.” + DomainName, NewSiteIP, “80″);

ManagementBaseObject inputParameters = oW3SVC.GetMethodParameters(”CreateNewSite”);
inputParameters["ServerComment"] = ConfigurationManager.AppSettings["SitePrefix"] + webSiteName;
inputParameters["ServerBindings"] = serverBindings;
inputParameters["PathOfRootVirtualDir"] = pathToRoot + webSiteName;
inputParameters["ServerId"] = siteID;

ManagementBaseObject outParameter = null;
outParameter = oW3SVC.InvokeMethod(”CreateNewSite”, inputParameters, null);
// return is like IIsWebServer=’W3SVC/2145288186′

sSiteID = Convert.ToString(outParameter.Properties["ReturnValue"].Value).Replace(”IIsWebServer=’W3SVC/”,””).Replace(”‘”,””);

ManagementObject site = new ManagementObject(_scope,
new ManagementPath(Convert.ToString(outParameter.Properties["ReturnValue"].Value)),
null);
#endregion

#region Remap ScriptMaps
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@”root\MicrosoftIISv2″,
“SELECT * FROM IIsWebVirtualDirSetting WHERE Path = ‘” + pathToRoot.Replace(@”\”,@”\\”) + webSiteName + “‘”) ;

foreach(ManagementObject queryObj in searcher.Get())
{
if (queryObj.Properties["ScriptMaps"] != null)
{
Object[] arrScriptMaps = (Object[])(queryObj["ScriptMaps"]);
foreach (Object arrValue in arrScriptMaps)
{
foreach (PropertyData data in ((ManagementBaseObject)arrValue).Properties)
{
if(Convert.ToString(data.Value).ToLower()==@”c:\windows\microsoft.net\framework\v1.1.4322\aspnet_isapi.dll”)
if (data.Name == “ScriptProcessor”)
data.Value = @”c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll”;
}
}
queryObj.SetPropertyValue(”ScriptMaps”, arrScriptMaps);
queryObj.Put();
}
}
#endregion

ManagementPath myPath = new ManagementPath();
myPath.Path = @”IIsWebVirtualDirSetting.Name=’W3SVC/” + siteID.ToString() + “/root’”;
ManagementObject oWebVDir = new ManagementObject(_scope, myPath, null);

oWebVDir.Properties["AppFriendlyName"].Value = “mah new app”;
oWebVDir.Properties["AccessRead"].Value = true;
//oWebVDir.Properties["ServerAutoStart"].Value = true;
oWebVDir.Properties["AuthFlags"].Value = 5; // Integrated Windows Auth.
oWebVDir.Properties["AccessScript"].Value = true;
oWebVDir.Properties["AuthAnonymous"].Value = true;
oWebVDir.Properties["AppPoolId"].Value = “MyAppPoolName”;
oWebVDir.Put();

site.InvokeMethod(”Start”, null);
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message + “
”);
HttpContext.Current.Response.Write(ex.StackTrace);
HttpContext.Current.Response.Write(ex.ToString());
HttpContext.Current.Response.End();
}

return sSiteID;
}

private static void CreatePhysicalDirectory(string pathToRoot, string webSiteName)
{
if (Directory.Exists(pathToRoot + webSiteName))
throw new Exception(”Error creating new website: Customer root directory already exists at ” + pathToRoot + webSiteName);
else
{
Directory.CreateDirectory(pathToRoot + webSiteName);
//StreamWriter indexFile = new StreamWriter(pathToRoot + webSiteName + @”\index.htm”, false, System.Text.Encoding.ASCII);
//indexFile.Write(”


Welcome to  ” + webSiteName + “

”);
//indexFile.Close();
}
}

///


/// Adds a host header value to a specified website. WARNING: NO ERROR CHECKING IS PERFORMED IN THIS EXAMPLE.
/// YOU ARE RESPONSIBLE FOR THAT EVERY ENTRY IS UNIQUE
///

/// The host header. Must be in the form IP:Port:Hostname /// The ID of the website the host header should be added to private static void AddHostHeader(string hostHeader, string websiteID)
{
DirectoryEntry site = new DirectoryEntry(”IIS://localhost/w3svc/” + websiteID);
try
{
//Get everything currently in the serverbindings propery.
PropertyValueCollection serverBindings = site.Properties["ServerBindings"];

//Add the new binding
serverBindings.Add(hostHeader);

//Create an object array and copy the content to this array
Object[] newList = new Object[serverBindings.Count];

serverBindings.CopyTo(newList, 0);
//Write to metabase

site.Properties["ServerBindings"].Value = newList;

//Commit the changes
site.CommitChanges();
}

catch (Exception e)
{
Console.WriteLine(e);
}
}

public static ManagementObject CreateServerBinding(string HostName, string IP, string Port)
{
ManagementScope _scope = new ManagementScope(@”\\WINDOWS\root\MicrosoftIISV2″);
_scope.Connect();

ManagementClass classBinding = new ManagementClass(_scope, new ManagementPath(”ServerBinding”), null);
ManagementObject serverBinding = classBinding.CreateInstance();
serverBinding.Properties["Hostname"].Value = HostName;
serverBinding.Properties["IP"].Value = IP;
serverBinding.Properties["Port"].Value = Port;
serverBinding.Put();
return serverBinding;
}

Categories: ASP.NET, IIS, c# Tags:

Creating a DNS Entry in Windows 20003 Std Edition with c# .NET

January 23rd, 2009 Michael Bell No comments

One of the websites I did in the past required me to be able to register a domain, create the site in IIS, add the DNS entries, and add email entries into HMail server. Here is the DNS server half of it. Of course you have to have permissions, but this is the method I used to get from A to B entering a new domain name into the DNS Server in Windows 2003 Standard Edition. You can tell by my exception block that this piece of code was executed from an ASP.NET Web Application:

///


/// Created an entry in DNS Server on a Windows 2003 Server
///

/// Domain name and TLD Extension /// IP Address the site belongs to in IIS /// IP Address of the DNS Server itself /// Email of the administrator for this domain public void new_Zone(string Domain, string AssignToIpAddr, string PrimaryServerIP, string AdminEmailName)
{
Domain = Domain.ToLower();
try
{
string[] ipArray;
ipArray = new string[1] { AssignToIpAddr };

//Create Foward Lookup Zone.
string sServerPath = “\\\\WINDOWS\\ROOT\\MicrosoftDNS”;
ManagementScope oScope = new ManagementScope(sServerPath);
oScope.Connect();
ManagementPath Path = new ManagementPath(”MicrosoftDNS_Zone”);
ManagementClass DnsZoneClass = new ManagementClass(oScope, Path, null);
ManagementBaseObject InputParams = DnsZoneClass.GetMethodParameters(”CreateZone”);

InputParams["ZoneName"] = Domain;
InputParams["ZoneType"] = 0;
InputParams["AdminEmailName"] = AdminEmailName;
InputParams["IpAddr"] = ipArray;
ManagementBaseObject OutParams = DnsZoneClass.InvokeMethod(”CreateZone”, InputParams, null);

#region A Records
ManagementPath newPath = new ManagementPath(”MicrosoftDNS_ATYPE”);
ManagementClass ARecordClass = new ManagementClass(oScope, newPath, null);
ManagementBaseObject ARecord = ARecordClass.GetMethodParameters(”CreateInstanceFromPropertyData”);ARecord["DnsServerName"] = “WINDOWS”;

ARecord["ContainerName"] = Domain;
ARecord["OwnerName"] = Domain;
ARecord["IPAddress"] = ipArray[0];

OutParams = ARecordClass.InvokeMethod(”CreateInstanceFromPropertyData”, ARecord, null);

ManagementClass dnsRRClass = new ManagementClass(@”\\” + System.Environment.MachineName + @”\root\MicrosoftDNS”, “MicrosoftDNS_ResourceRecord”, null);
ManagementBaseObject inParams = dnsRRClass.GetMethodParameters(”CreateInstanceFromTextRepresentation”);

inParams["DnsServerName"] = “.”;
inParams["ContainerName"] = Domain;
inParams["TextRepresentation"] = “www.” + Domain + ” IN A ” + ipArray[0];
OutParams = dnsRRClass.InvokeMethod(”CreateInstanceFromTextRepresentation”, inParams, null);

dnsRRClass = new ManagementClass(@”\\” + System.Environment.MachineName + @”\root\MicrosoftDNS”, “MicrosoftDNS_ResourceRecord”, null);
inParams = dnsRRClass.GetMethodParameters(”CreateInstanceFromTextRepresentation”);

inParams["DnsServerName"] = “.”;
inParams["ContainerName"] = Domain;
inParams["TextRepresentation"] = “mail.” + Domain + ” IN A ” + ipArray[0];
OutParams = dnsRRClass.InvokeMethod(”CreateInstanceFromTextRepresentation”, inParams, null);

#endregion
}
catch (Exception ex)
{
//throw;
HttpContext.Current.Response.Write(ex.Message + “
”);
HttpContext.Current.Response.Write(ex.StackTrace);
HttpContext.Current.Response.Write(ex.ToString());
HttpContext.Current.Response.End();
}
}

Categories: ASP.NET, DNS, IIS, c# Tags: