Hi,
I have requirement to validate URL i.e. If user put invalid URL then application should show generic error page.
For ex: when user enter URL in browser like ie8
correct URl is: www.abc.com/hr/test.aspx (then test page should display)
if user puts: www.abc.com/hr/xyz (with extension or without extension) then application should redirect to generic error page.
I am using asp.net 4.0 and my application have multiple folders like admin/user etc and each folder have multiple web pages.
Please suggest how can I achieve this functionality.
Thanks
Loading
Jignesh TrivediPosted Sep 24, 2013, 1:34 AM
hi,
Not sure why your code is hangeup...
with the help of HttpContext.Current.Request.Url you can find out current requested url.
In begin request you can check this url and vali it...
void Application_BeginRequest(Object source, EventArgs e)
{
var url = HttpContext.Current.Request.Url.AbsoluteUri;
// validate thi surl using Regex and re found faulty then redirect... it
}
hope this will help you.
Areeb QuaziPosted Sep 23, 2013, 11:54 AM
I already added customError in web.config. but when user add URL like http://www.abc.com/test.aspx/xyz in this case it's not hitting filenotfound.aspx.
Note: http://www.abc.com/test.aspx is valid URL.
I tryied secound solution given by you in global.aspx application_authenticateRequest and
application_beginRequest also. but application will hanged. after using (var response....) line cursor goes to application_authenticateRequest and then using (var response....) line till application hanges
Please suggest what else I need to do.
Abhishek JainPosted Sep 20, 2013, 4:28 AM
One more way is to add entry for this in Web.Config;
Here we are setting if the Page is not found, it means that if the URL is wrong then Redirect the user on Error Page FilenotFound.aspx.
Regards
AJ
Iftikar HussainPosted Sep 20, 2013, 4:22 AM
Regards,
Iftikar
Areeb QuaziPosted Sep 20, 2013, 4:16 AM
Iftikar HussainPosted Sep 20, 2013, 2:36 AM
Try like this
{
//do your staff
}
else
{
//redirect to error page
}
Regards,
Iftikar
Abhishek JainPosted Sep 20, 2013, 2:28 AM
string url;
//Set URL in the string.
Regards
AJ