我创建了一个webapp和一个控制台应用程序以在IIS中注册该网站。似乎根本没有问题。
这是我用于在IIS中注册网站的代码。
Dim manager As New ServerManager
Dim site As Site = manager.Sites.Add("MyControl", "http", "*:80:test.localhost", "C:\\inetpub\wwwroot\MyControl")
manager.ApplicationPools.Add("MyControl")
site.ApplicationDefaults.ApplicationPoolName = "MyControl"
manager.CommitChanges()
该站点已在IIS中正常注册。键入为http,主机名为test.localhost,端口为80,ip为*。像预期的那样。
我已经修改了主机文件,并添加了以下行:127.0.0.1 test.localhost
这样,导航到http://test.localhost将解决重定向到IIS上我们站点的问题。
这应该意味着重定向到inetpub / wwwroot / MyControl根目录中的默认页面default.html。
但是,这不会发生。我得到一个空白页面,没有标题,来源为空白,但找不到页面。此外,如果我自己导航至http://test.localhost/default.html,则会得到空白页,但标题为:MyControl。现在,如果我查看源代码,我可以看到它找到了文件,但是什么也没有显示。
如果我在IIS中手动设置网站,那没有问题。
任何想法,将不胜感激。
编辑:
到现在为止还挺好。现在,我将其与上述代码一起使用。你怎么了 我没有线索。
现在,我需要使用相同的网站,但要使用SSL证书进行安装。
我正在使用此代码
Module Main
<DllImport("advapi32.DLL", SetLastError:=True)>
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.OpenExistingOnly Or 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) 'Sti til SSL certifikat og password til at installere dette
store.Add(certificate)
'Opret en manager og en config til oprettelse af site
Dim 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 Sub
再次。该代码正在IIS中注册网站,并且可以很好地设置证书。绑定看起来像这样
我再次修改了主机文件,添加了以下行 127.0.0.1 webmail.jcdhotel.dk
我可以转到链接https://webmail.jcdhotel.dk并接收空白页,源为空白。然后,我可以转到https://webmail.jcdhotel.dk/default.html,将设置标题,现在可以检查源,但页面仍为空白。
再次感谢您的任何帮助,并在此先感谢您!
编辑:
新讯息。通过手动尝试使用SSL证书将网站添加到IIS,我收到以下错误:
希望这将有助于阐明该问题。
编辑:
最后编辑,希望:D
我现在可以使用SSL证书手动添加绑定。问题是由于证书安装不正确。这使我进入最后的障碍。
使用vb.net将证书添加到商店时。如何检查“允许导出证书”?-由于这解决了手动添加证书时的问题。
尝试了一切之后,我最终得到了这段代码
<DllImport("advapi32.DLL", SetLastError:=True)>
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
问题出在行中
Dim site As Site = manager.Sites.Add("MyControl", "*:443:webmail.jcdhotel.dk", "C:\inetpub\wwwroot\MyControl", certificate.GetCertHash())
我习惯了C#以及如何转义字符串。所以我错误地弹出了一个额外的\,使行看起来像这样
Dim site As Site = manager.Sites.Add("MyControl", "*:443:webmail.jcdhotel.dk", "C:\\inetpub\wwwroot\MyControl", certificate.GetCertHash())
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句