Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to set custom error pages on automated site creation

Posted on 2007-11-20
7
Medium Priority
?
312 Views
Last Modified: 2012-05-05
I've attached a snippet of the code I'm using to create the site in IIS. The full script currently creates a site successfully. However, I wanted to modify it so that it set custom error pages.

From googling and reading the Microsoft Knowledge Base I found that the IIsWebVirtualdirSettings object allows HTTPErrors to be set. When I try assign a string to oVirtualDir.HTTPErrors it gives me a type mismatch error.
From further reading it sounds like I'm suppose to assign an array to HTTPErrors, but that didn't seem to work either.

If someone could show me how to properly assign the error page settings to oVirtualdir.HTTPErrors I would appreciate it.
set oLocator = CreateObject("WbemScripting.SWbemLocator")
set oProvider = oLocator.ConnectServer("localhost", "root/MicrosoftIISv2")
set oService = oProvider.Get("IIsWebService='W3SVC'")
 
oBindings = Array(0)
Set oBindings(0) = oProvider.Get("ServerBinding").SpawnInstance_()
oBindings(0).IP = ""
oBindings(0).Port = "80"
oBindings(0).Hostname = siteName
 
ReDim Preserve oBindings(1)
Set oBindings(1) = oProvider.Get("ServerBinding").SpawnInstance_()
oBindings(1).IP = ""
oBindings(1).Port = "80"
oBindings(1).Hostname = "www." & siteName
 
Dim sSiteObjectPath
sSiteObjectPath = oService.CreateNewSite(siteName, oBindings, wwwPath)
If Err Then
	error.Add "Site Creation", "*** Error Creating Site: " & Hex(Err.Number) & ": " & Err.Description & " ***"
	WScript.Quit(1)
End If
 
Set oPath = CreateObject("WbemScripting.SWbemObjectPath")
oPath.Path = sSiteObjectPath
sSitePath = oPath.Keys.Item("")
 
Set oVirtualDir = oProvider.Get("IIsWebVirtualDirSetting='" & sSitePath & "/ROOT'")
oVirtualDir.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
oVirtualDir.EnableDefaultDoc = True
 
 
oVirtualDir.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
oVirtualDir.AccessFlags = 513 ' read, script
oVirtualDir.AppFriendlyName = "Root Application"

Open in new window

0
Comment
Question by:Shroder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Author Comment

by:Shroder
ID: 20322004
A correction to the information above. The object wasn't ErrorPages. It was HTTPErrors.
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 20322866
OK, I'm looking into this, and you are right and wrong. Yes, HttpErrors[] is an array. But not of string. It is an array of HttpError... Now, if I'm reading some of this stuff right, you also need to put in the full list of handlers even if you modify one. So, try iterating this list into your HttpErrors array. Each line is a new array item...

"400,*,FILE,C:\WINDOWS\help\iisHelp\common\400.htm"
"401,1,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm"
"401,2,FILE,C:\WINDOWS\help\iisHelp\common\401-2.htm"
"401,3,FILE,C:\WINDOWS\help\iisHelp\common\401-3.htm"
"401,4,FILE,C:\WINDOWS\help\iisHelp\common\401-4.htm"
"401,5,FILE,C:\WINDOWS\help\iisHelp\common\401-5.htm"
"401,7,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm"
"403,1,FILE,C:\WINDOWS\help\iisHelp\common\403-1.htm"
"403,2,FILE,C:\WINDOWS\help\iisHelp\common\403-2.htm"
"403,3,FILE,C:\WINDOWS\help\iisHelp\common\403-3.htm"
"403,4,FILE,C:\WINDOWS\help\iisHelp\common\403-4.htm"
"403,5,FILE,C:\WINDOWS\help\iisHelp\common\403-5.htm"
"403,6,FILE,C:\WINDOWS\help\iisHelp\common\403-6.htm"
"403,7,FILE,C:\WINDOWS\help\iisHelp\common\403-7.htm"
"403,8,FILE,C:\WINDOWS\help\iisHelp\common\403-8.htm"
"403,9,FILE,C:\WINDOWS\help\iisHelp\common\403-9.htm"
"403,10,FILE,C:\WINDOWS\help\iisHelp\common\403-10.htm"
"403,11,FILE,C:\WINDOWS\help\iisHelp\common\403-11.htm"
"403,12,FILE,C:\WINDOWS\help\iisHelp\common\403-12.htm"
"403,13,FILE,C:\WINDOWS\help\iisHelp\common\403-13.htm"
"403,15,FILE,C:\WINDOWS\help\iisHelp\common\403-15.htm"
"403,16,FILE,C:\WINDOWS\help\iisHelp\common\403-16.htm"
"403,17,FILE,C:\WINDOWS\help\iisHelp\common\403-17.htm"
"403,18,FILE,C:\WINDOWS\help\iisHelp\common\403.htm"
"403,19,FILE,C:\WINDOWS\help\iisHelp\common\403.htm"
"403,20,FILE,C:\WINDOWS\help\iisHelp\common\403-20.htm"
"404,*,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm"
"404,2,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm"
"404,3,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm"
"405,*,FILE,C:\WINDOWS\help\iisHelp\common\405.htm"
"406,*,FILE,C:\WINDOWS\help\iisHelp\common\406.htm"
"407,*,FILE,C:\WINDOWS\help\iisHelp\common\407.htm"
"412,*,FILE,C:\WINDOWS\help\iisHelp\common\412.htm"
"414,*,FILE,C:\WINDOWS\help\iisHelp\common\414.htm"
"415,*,FILE,C:\WINDOWS\help\iisHelp\common\415.htm"
"500,12,FILE,C:\WINDOWS\help\iisHelp\common\500-12.htm"
"500,13,FILE,C:\WINDOWS\help\iisHelp\common\500-13.htm"
"500,15,FILE,C:\WINDOWS\help\iisHelp\common\500-15.htm"
"500,16,FILE,C:\WINDOWS\help\iisHelp\common\500.htm"
"500,17,FILE,C:\WINDOWS\help\iisHelp\common\500.htm"
"500,18,FILE,C:\WINDOWS\help\iisHelp\common\500.htm"
"500,19,FILE,C:\WINDOWS\help\iisHelp\common\500.htm"

Obviously, change the ones you need to what you need them to be.
0
 

Author Comment

by:Shroder
ID: 20323075
I did see it mentioned that it's an array of HTTPError. I didn't know how to make the array of HTTPError/put the above values into the object.

Thank you for your help so far.

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:Shroder
ID: 20351047
I have seen a way to create an instance of the HTTPError object through Asp.net. I have been able so far to find a way through classic ASP.

Any ideas?
0
 
LVL 9

Accepted Solution

by:
CCongdon earned 2000 total points
ID: 20351351
I *think* you just have to cram each line of text into an iteration of the HTTPErrors collection. My understanding is that a comma delimted list gets 'cast' into an HTTPError object on the fly. Something I read on a newsgroup:

'On common gotcha is that this is an multi-string property define all HttpErrors.'

The downside is that I believe you have to define ALL the errors to get it to work right.

I'm a little out of my element here because I've never scripted IIS management, so I'm just attemtping to lend you my research skills at solving this problem, so I apologize if I am a bit clumsy in my attempts at helping.

Hmmm, another thing I am seeing is that people are calling the HttpError object a LIST data type.

You might do a search for something called ADSUTIL.VBS. Apparently, this is a script that allows you to set/delete LIST properties. That could give you some pointers.

David Wang's blog over at MSDN has some examples on manipulating individual items in a LIST.

http://blogs.msdn.com/david.wang/archive/2004/12/02/273681.aspx

You might also check out a script called IISCnfg.vbs. It is used to import/export portions of the metabase. I would assume it moves error messages as part of it. You might even be able to jury rig it into accepting an XML input to create your IIS config.
0
 

Author Comment

by:Shroder
ID: 20351652
Thank you for the info. I will check out those scripts and see what I can find.

I'm a little fuzzy on what a "multi-string property is". I'm not sure if that means the object is actually an array of strings.
I've tried stuffing just a string into httpError and an array of strings.

Hopefully I can find the answer in one of those scripts.

Thanks again to both of you. Just confirming things helps a ton!
0
 

Author Comment

by:Shroder
ID: 20384499
I'm going to close this for now since I probably wont be able to look into it further in the near future.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question