since 1997 a place for my stuff, and if it helps you then so much the better

 
...
...

Default pages


Time to get the general purpose stuff wrapped up.

Since we're now going to be starting to use real ASP.Net pages, it's smart to put in a simple web.config so that we can see any errors along the way. Use nano to create the file...

sudo nano /home/kilgore/sites/asdf/web.config

... and add the customErrors node with the mode set to Off.

<?xml version="1.0"?>
<configuration>
   <system.web>
      <compilation debug="true">
      </compilation>
      <customErrors mode="Off">
      </customErrors>
   </system.web>
</configuration>

Before release you'll of course change the compilation mode and set the customErrors mode value to "RemoteOnly", and use the text-based Lynx browser to view .Net issues when logged onto the server. For right now, we'll assume that you're testing your overall setup from off-box clients so having customErrors "Off" makes work easier.

Setting the default page

This is easy, just nano the /etc/apache2/sites-available/[site vhost file] and add a DirectoryIndex line for the page that you want to appear if no page is specified in the request.

The only question you have to ask yourself is do you want this to be a static page of non-dynamic html or an ASP.Net page. Most likely, since you're here at smithvoice.com, you'll want it to be an ASPX page... but just remember that if it is a managed page and if you have any serverside issues that kill Mono's ASP.Net (such as a mistake in the web.config) your users will see an unhandleable 500 error *from Mono* that won't bubble up to be redirected by Apache. Standard stuff, same as MS.Net, but something to consider.

For our example, we will cross our fingers about .Net service errors and use an ASPX named "defpage.aspx" for our default.

sudo nano /home/kilgore/sites/asdf/defpage.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
   protected void Page_Load(object sender, EventArgs e)
   {
      lblInfo.Text = String.Format("I am the asp.net site default page<br />the time now is {0}",
           DateTime.Now.ToLongTimeString());
   }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
     <form id="form1" runat="server">
        <asp:Label ID="lblInfo" runat="server"></asp:Label>
     </form>
</body>
</html>

To have that page be our default, add the line to /etc/apache2/sites-available/asdf

<VirtualHost *:80>
   ServerName www.asdf.com
   DocumentRoot /home/kilgore/sites/asdf
   DirectoryIndex  defpage.aspx
</VirtualHost>

Because the change was at the Apache level, not the Mono level, you have to force Apache to be aware of it. Reload will do that for you.

 sudo /etc/init.d/apache2 reload

Now give http://www.asdf.com a client test.

Take note that we altered the asdf website configuration file in /etc/apache2/sites-available/asdf. We didn't do it in /sites-enabled/ and we didn't have to do a force after the change with a2dissite and a2ensite.

Once a site is enabled with a2ensite, any changes you make to its configuration file in /sites-available/ will get copied over to the corresponding /sites-enabled/ file with a reload (or restart or stop&start) of the Apache service. You can verify this by the fact that the change went into effect ;-), and also by looking at the /sites-enabled/ file:



Coming next: Handling site errors.


Robert Smith
Kirkland, WA

added to smithvoice april 1st 2009


...
...

"In theory, theory and practice are the same. In practice, they are not." -Albert Einstein