views:

1059

answers:

3

Is it possible to set an .ashx file as the starting (or default) page for a web application? If so, how is it done?

Edit - Some good suggestions. I have added "Default.ashx" to the IIS Default Documents and "Enabled Default Document" on the website, however, it only displays a directory listing even though I have disabled directory browsing.

Any other suggestions would be appreciated. (IIS Version 5.1)

Edit - Restarted IIS and it works.

Question - May I also ask if it is possible to set the start page to an .ashx from within Visual Studio 2005? I can't seem to debug from within Visual Studio after doing this.

Answer - In the Application Properties a "Start Action" can be selected under the "Web" tab. In fact, it also allows the selection of which Server/Port and Debugger to use. Very cool.

A: 

Just set it on the default application server like IIS, if your point is to create a handler to ashx youu could do as it follows:

So, start off by creating rss.ashx

<!--WebHandler Language="C#" Class="KBMentor2.RSSHandler"-->

Now lets have a look at the handler class:

RSSHandler.cs

namespace KBMentor2
{
    using System;
    using System.IO;
    using System.Web;


    public class RSSHandler : IHttpHandler
    {
     public void ProcessRequest (HttpContext context)
     {   
      context.Response.ContentType = "text/xml";
      context.Response.ContentEncoding = System.Text.Encoding.UTF8;

      string sXml = BuildXMLString(); //not showing this function, 
      //but it creates the XML string

      context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(600));
      context.Response.Cache.SetCacheability(HttpCacheability.Public);
      context.Response.Write( sXml );
     }

     public bool IsReusable
     {
      get { return true; }
     }

    }

}

And there you have it. Looks pretty much like the first code we created, doesn't it? As for caching, you can solve it by accessing the Cache object from your code, see the context.Response.Cache calls.

source for the code is: aspcode.net

Kamia
A: 

you may just need to add the 'page'.ashx file to the list of default files in the IIS server settings. you'll probably be able to deploy it just like any other web application.

John Boker
+4  A: 
chakrit