In Asp.Net, check for an aspx page before redirecting to it?

How to check for an aspx page before trying to redirect it, so I can handle this case in my C # code?

Response.Redict("~/SomePage.aspx")

But I want to make sure that the page really exists before I call it. In the end, this works from a string, so maybe I have a type or something else, or maybe I haven't created this page yet.

+3
source share
4 answers

Make File.Exists on the page.

  if(File.Exists(Server.MapPath("~/SomePage.aspx")))
    Response.Redirect("~/SomePage.aspx");

You need to use the System.IO namespace.

+8
source
File.Exists(Server.MapPath("~/SomePage.aspx"))
+3
source

, , , .

0
System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists("~/SomePage.aspx");
0

Source: https://habr.com/ru/post/1720293/


All Articles