Reputation: 9995
How can I check for the existence of an aspx page before attempting to redirect to it, so I can handle that case in my C# code?
Response.Redict("~/SomePage.aspx")
But I want to make sure that page really does exist before I call it. It works off of a string after all, so maybe I have a type or something, or maybe I have not created that page yet.
Upvotes: 3
Views: 3908
Reputation: 7941
System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists("~/SomePage.aspx");
Upvotes: 0
Reputation: 70012
Do a File.Exists on the page.
if(File.Exists(Server.MapPath("~/SomePage.aspx")))
Response.Redirect("~/SomePage.aspx");
You'll need to use the System.IO namespace.
Upvotes: 8
Reputation: 23016
If the file is on the same server then You can check if the file exists and then redirect the user.
Upvotes: 0