Set .ashx as start “page” for web application

别等时光非礼了梦想. 提交于 2019-12-11 17:52:50

问题


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.


回答1:


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:

.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/454343/set-ashx-as-start-page-for-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!