Question

I have a url like : 120.xxx.xxx.xxx/myfile.pdf ,but it doesn't exist

and it not direct to my error.aspx

Can someone to tell me whats happened

and My web.config code

<customErrors mode="On" defaultRedirect="~/error.aspx">
      <error statusCode="404" redirect="~/error404.aspx"/>
</customErrors>
Était-ce utile?

La solution

It is happening because this is a static file and by default will bypass ASP.Net and just get served up by IIS. Try adding this to your <system.webServer> section of the web.config:

<handlers>
      <add name="PDFHandler-Integrated" path="*.pdf" verb="GET"
        type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler"
        requireAccess="Script" preCondition="integratedMode" />
</handlers>

Doing this will make it go through the ASP.Net pipeline so you can apply other functionality like Authentication/Role restrictions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top