asp.net 404 error handling from a particular folder RRS feed

  • Question

  • User1804579801 posted

    Dear All,

    I want to display a particular message if the user tries to find a file from 

    a particular folder from site

    mysite/folder/file.pdf  then display the message "XXX" in place of 404 message



    Friday, January 24, 2020 12:30 PM

All replies

  • User281315223 posted

    By default, if nothing exists in the folder, your site should issue a 404. If you explicitly want to hide a folder / file from being accessed (which would throw a 404), you could just configure the directory (or file) in either IIS or your web.config via hiddenSegments:

                    <add segment="yourDirectoryToHide" />

    Friday, January 24, 2020 9:58 PM
  • User1804579801 posted

    Thanks for the replay.

    But I don't want to hide the folder. Actually, in my folder I have some PDF files for version 1.0 now I am releasing another latest version 1.0.1 so if the users try to access the old files 

    i.e., filename.1.0.pdf then a message should come "please login to the site and download the latest version of the file" this message should come instead of 404 message only when user trying to access the files from this folder  any other files  or aspx pages if he is accessing then normal 404 message will come which I redirected to a specific page in web config

    as below

    <customErrors mode="On" defaultRedirect="pagenotfound.aspx">
    <error statusCode="404" redirect="pagenotfound.aspx" /> </customErrors>

    My IIS server IIS 7

    Please suggest 

    Monday, January 27, 2020 5:00 AM
  • User1535942433 posted

    Hi nagapavanich,

    Accroding to your description,I suggest you could insert  url rewrite in web.config and come out error 404.

    More details,you could refer to below articles:


    Best regards,

    Yijing Sun

    Thursday, January 30, 2020 9:09 AM