0

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.

user50612
  • 3,098
  • 3
  • 25
  • 20
  • I think you can also define default documents in web.config as stated in my answer, the dev webserver should respect that. – chakrit Jan 18 '09 at 12:24

3 Answers3

5

Add your ASHX page and make sure you move it to the top of the list.

And in IIS7, you can specify it in web.config:

<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <add value="my_default_page.ASHX" />
        </files>
    </defaultDocument>
</system.webServer>    

More information in this blog post

EDIT: As @waves discovered, you might need to restart IIS after the configuration.


To disable directory browsing, uncheck the "Directory Browsing" checkbox:

.

ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
chakrit
  • 61,017
  • 25
  • 133
  • 162
  • I have lost the original content of the screenshot files, if anyone can make new screenshots, i can find a better host for it. – chakrit Jul 09 '13 at 04:52
0

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

Diego Magalhães
  • 725
  • 1
  • 10
  • 32
0

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
  • 82,559
  • 17
  • 97
  • 130