Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After trying, what seemed to be everything, I ended up with this code</p> <pre><code>&lt;DllImport("advapi32.DLL", SetLastError:=True)&gt; Public Function LogonUser(ByVal username As String, ByVal domain As String, ByVal password As String, ByVal logonType As Integer, ByVal logonProvider As Integer, ByRef token As IntPtr) As Integer End Function Sub Main() 'Load indstillinger fra app.config Dim sslPath As String = ConfigurationManager.AppSettings("sslPath") Dim sslPassword As String = ConfigurationManager.AppSettings("sslPassword") Dim remoteUsername As String = ConfigurationManager.AppSettings("remoteUsername") Dim remotePassword As String = ConfigurationManager.AppSettings("remotePassword") 'Lav en store, således at vi kan få fat i vores ssl certifikat Dim store As X509Store = New X509Store(StoreName.My, StoreLocation.LocalMachine) store.Open(OpenFlags.ReadWrite) 'Generer credentials til impersonation Dim adminToken As IntPtr = IntPtr.Zero Dim admin As WindowsIdentity = Nothing Dim context As WindowsImpersonationContext = Nothing 'Login med den specificerede bruger LogonUser(remoteUsername, System.Environment.MachineName, remotePassword, 9, 0, adminToken) '9 afspejler logintype og 0 afspejler loginprovider - Ingen idé om hvad det har af betydning admin = New WindowsIdentity(adminToken) context = admin.Impersonate() 'Import af SSL certifikat Dim certificate As X509Certificate2 = New X509Certificate2(sslPath, sslPassword, X509KeyStorageFlags.PersistKeySet) 'Sti til SSL certifikat og password til at installere dette store.Add(certificate) 'Opret en manager og en config til oprettelse af site Using manager As New ServerManager Dim config As Microsoft.Web.Administration.Configuration = manager.GetApplicationHostConfiguration() 'Opret site i IIS med det valgte certifikat Dim site As Site = manager.Sites.Add("MyControl", "*:443:webmail.jcdhotel.dk", "C:\inetpub\wwwroot\MyControl", certificate.GetCertHash()) 'Kræv SSL Dim accessSection As Microsoft.Web.Administration.ConfigurationSection = config.GetSection("system.webServer/security/access", "MyControl") accessSection("sslFlags") = "Ssl" 'Opret en applicationpool specifikt til MyControl og sæt denne til default manager.ApplicationPools.Add("MyControl") site.ApplicationDefaults.ApplicationPoolName = "MyControl" 'Luk store store.Close() 'Gem ændringer og revert impersonation manager.CommitChanges() context.Undo() End Using End Sub </code></pre> <p>The problem was in the line</p> <pre><code>Dim site As Site = manager.Sites.Add("MyControl", "*:443:webmail.jcdhotel.dk", "C:\inetpub\wwwroot\MyControl", certificate.GetCertHash()) </code></pre> <p>I'm used to C# and how you escape strings. So I had falsely popped in an extra \ making the line look like this </p> <p><code>Dim site As Site = manager.Sites.Add("MyControl", "*:443:webmail.jcdhotel.dk", "C:\\inetpub\wwwroot\MyControl", certificate.GetCertHash())</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload