Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to catch page not found error when redirecting

How to catch page not found error when redirecting

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DotNetXenon
    wrote on last edited by
    #1

    There is a virtual path(http://server1/files/test.xls). From asp.net web app, I have to redirect to above path. If test.xls does not exist in the path, I have to display unauthorized page. I tried using if (File.Exists(Server.MapPath(URL))) but it gives an error "it is not a valid virtual path".

    ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

    B S 2 Replies Last reply
    0
    • D DotNetXenon

      There is a virtual path(http://server1/files/test.xls). From asp.net web app, I have to redirect to above path. If test.xls does not exist in the path, I have to display unauthorized page. I tried using if (File.Exists(Server.MapPath(URL))) but it gives an error "it is not a valid virtual path".

      ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      You have to try check if exists file like this: if (File.Exists("C:\\Directory\\FileName.txt") ...


      I Love T-SQL

      1 Reply Last reply
      0
      • D DotNetXenon

        There is a virtual path(http://server1/files/test.xls). From asp.net web app, I have to redirect to above path. If test.xls does not exist in the path, I have to display unauthorized page. I tried using if (File.Exists(Server.MapPath(URL))) but it gives an error "it is not a valid virtual path".

        ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

        S Offline
        S Offline
        Sankar Komma
        wrote on last edited by
        #3

        Try this if(File.Exitst(Server.MapPath("~/files/test.xls"))) { Redirect to the path; } else { Redirect to Unauthorized page. } Server.MapPath append the specified path to root path. ex: http://server1 say root path then in if contion check for the path 'http://server1/files/text.xls'

        smile :-)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups