Quantcast
Channel: Configuration & Scripting
Viewing all articles
Browse latest Browse all 780

How to execute myself code when access an invalid URL

$
0
0

IIS7.5 in Win7 64bit.

1) I deployed a local website, SourceBrowser, set its Physical Path to C:\SourceEngine\Web

2) When access http://localhost/SourceBrowser/Project1

     The Project1 does not exist in my Physical Path C:\SourceEngine\Web

3) But I want to catch this access(http://localhost/SourceBrowser/Project1) in my .cs code,  and handle some logic then response a content to user.

4) I already config like below in Web.config file.

<system.web>  

<httpHandlers>

      <add verb="GET,POST" path="**" validate="false" type="TDF.SourceEngine.Web.HandlerFactory, TDF.SourceEngine" />
</httpHandlers>
</system.web>

<system.webServer>
<handlers>
<add name="ScriptMapWild" path="*" verb="GET,POST" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Either" requireAccess="None"/>
</handlers>
</system.webServer>

5) TDF.SourceEngine.Web.HandlerFactory is my Handler.

public class HandlerFactory : IHttpHandlerFactory
{
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
return new SourceHandler();
}

}

6) Above settings can handle this http://localhost/SourceBrowser,   it will going to my Handler.

but not handle http://localhost/SourceBrowser/Project1  this will get en error "HTTP Error 404.0 - Not FoundThe resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

How to do right settings in IIS or Web.config?


Viewing all articles
Browse latest Browse all 780

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>