tags:

views:

19

answers:

1

I'm using Wix to install my web application, and it includes a Silverlight app. Because of cross-domain restrictions, I need to install a ClientAccessPolicy file to ensure that the Silverlight app can talk to the included web services.

Unfortunately, ClientAccessPolicy.xml has to be available from the root of the site, so I can't just place it with my web services or web site. e.g.

Works: http://someserver/ClientAccessPolicy.xml
Doesn't work: http://someserver/MyApp/ClientAccessPolicy.xml

How can I find the directory for the IIS "Default Web Site" to copy the file there as part of the install?

+1  A: 

Unfortunately, you have to author a custom action for this. It seems to be just a simple immediate action, which is to find the correct directory path and put it to a property.

UPDATE: The sample C# code for this might look like this:

 DirectoryEntry website = new DirectoryEntry(string.Format("IIS://localhost/w3svc/{0}/Root", siteID));
 if (website != null)
 {
    string sitePath = website.InvokeGet("Path") as string;
    if (sitePath != null)
    {
       session["SITE_PATH"] = sitePath;
       return ActionResult.Success;
    }
 }
 return ActionResult.Failure;

It assumes that you know the siteID in some way. If it's not always default web site, it is better to let the user choose, for instance. But that's another story.

Note also that this code requires special privileges to access DirectoryEntry - the regular user is not enough.

Hope this helps.

Yan Sklyarenko
I figured an action may be necessary, the only code I've seen so far to actually find the value is vbscript however (http://stackoverflow.com/questions/1835929/need-to-find-default-web-sites-home-directory-in-iis). Any ideas how to do this from C#?
Simon Steele
I've added some sample code for example.
Yan Sklyarenko