开发者

Can I stop ASP.NET from returning 'The resource cannot be found.'?

I have installed an HttpModule into my web app that will handle all requests with a given file extension.

I want ASP.NET to handle all requests with the extension, regardless of whether there is an underlying file on disk. So, when I added the extension to the 'Application Extension Mappings', I unchecked the 'Verify that file exists' checkbox.

However, this just transfers the file check to ASP.NET rather IIS, so I just get a different error page when requesting URLs with the file extension.

Is there a way to preempt this ASP.NET file checking and intercept the req开发者_如何学Pythonuests?


You need to create an HttpHandler instead of an HttpModule. Add the HttpHanlder extension to your web config and then all requests to the server for that extension will be directed to your handler.

<httpHandlers>
    <add verb="*" path="*.ext" type="Domain.Model.MyHttpHandler" />
</httpHandlers>

The handler can then serve up whatever it wants. If it's an unknown filetype you will need to advise IIS of the type and that it is handled by ASP.NET.

Here is a nice quick start guide


In the Global.asax you can handle the BeginRequest event.

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

You will most likely want to modify the Reponse object to make sure you can give a custom page or redirect accordingly.

If you do not have a Global.asax in your project just go to Add New Item > Global Application Class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜