I have Existing MVC Web Application url physically not exists (i.e. MyMVCSite/mypage.aspx. i need to redirect page on "error page" if invalid aspx enter by user, which not working in .aspx page condition but when unvalid action enter its work
-) MVCSite/InvalidePage --> Redirect to error Page MVCSite/error
-) MVCSite/InvalidePage.aspx --> Redirect to HomePage as Page MVCSite/InvalidePage.aspx
I need last condition also redirects to Page MVCSite/error So this condition is also tried by me as URL physically not exist its also not work here...
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (sUrl.EndsWith(".aspx"))
{
string[] path = sUrl.Split('/');
if (!System.IO.File.Exists(Server.MapPath("test.aspx")))
Response.Redirect("error");
}
}
Furthermore i am unable to apply 404 exception in Application_Error event in Global.asax, this exception occurs many time so there is also a checkd of 404 - File does not exist due to some unknow reasons may be some images, css file not find which currently very hard to find
protected void Application_Error()
{
if (objException.Message != "File does not exist.") { //..... }
}
I am also apply custom errors in Web.config which also not work
<customErrors mode="Off">
<error statusCode="404" redirect="Error/Index" />
</customErrors>
Currently error page only occur when action name is wrong but if page name is wrong it redirect us on home page with wrong url Please advice many any other option using that i would resolve this issue