Home > Posts > Set default document for IIS via web.config at Silverlight Web project

Set default document for IIS via web.config at Silverlight Web project

When you tell the Visual Studio IDE to generate a web project (instead of just using an autogenerated page) for a Silverlight project, it creates a project named SilverlightAppName.Web with a SilverlightAppNameTestPage.aspx (ASP.net) and an SilverlightAppNameTestPage.html. Either one can be served from a web server (obviously the .aspx one from IIS or any web server that supports ASP.net at the server-side) to run the Silverlight app in the browser, or for debugging from within Visual Studio (with the included test web server [Cassini] or IIS).

Note that at that Web project’s Properties, there’s a tab Silverlight applications, where Silverlight apps hosted by that Web project are listed. If you add more there, Visual Studio will generate respective pages for them, in the pattern mentioned above.

By right clicking one of those two pages you can select “Set as Start Page” to set the default page that “Start” or “Start without debugging” uses. However that setting isn’t replicated to the web.config file automatically so that after publishing (by right clicking the web project and selecting “Publish”) that Web project to say a subfolder under “wwwroot” of IIS (or deeper in the web folders hierarchy).

If it was doing so, you would be able to just visit that folder and have IIS (or any other web server that supports the web.config scheme) serve the wanted page as the default document (instead of showing a can’t browse folder error or displaying the folder contents if Directory Browsing has been enabled at IIS console for that folder or some ancestor of it [and has not been overridden to disable at that folder])

However, you can edit web.config yourself to achieve that, like below:

<?xml version="1.0"?>
<!--   For more information on how to configure your ASP.NET application, 
please visit   http://go.microsoft.com/fwlink/?LinkId=169433   --> <configuration>
<system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
<defaultDocument>
<files>
       <clear />
        <add value="
SilverlightAppNameTestPage.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>

</configuration>
Advertisements
  1. 2013/04/12 at 17:58

    Excellent – thank you! I’ve been tearing my hair out having to log in to the IIS server and reset the default document for my Silverlight application every time I publish from VS. No-one else seems to have understood the question that you have answered here!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: