Answered by:
Response.Redirect

Question
-
User-1664485818 posted
Hi everyone, within my controller I have a method to check some logic, if false the user needs to be redirected to another website,
but I receive the following error;
"The required anti-forgery form field "__RequestVerificationToken" is not present."
If i replace Response.Redirect with a return Redirect to a page within the website everything works ok, but I need to redirect the user to another website...
Any help much appreciated as always :)
[HttpPost] [ValidateAntiForgeryToken] public ActionResult ValidateApplication(bool status) { if (status != true) { Response.Redirect("https://somewebsite"); } else { return RedirectToUmbracoPage(); } }
Tuesday, January 8, 2019 5:10 PM
Answers
-
User475983607 posted
This is the url when the application fails
http://localhost:56973/umbraco/Surface/RegisterNewUser/https%3a/google.com
return RedirectToAction("https://google.com");
Of course it fails and of course the Google URL is appended to the URL as that's how RedirectToAction works.
Use...
return Redirect("https://www.google.com");
...when redirecting outside the current application or to a specific URL.
https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.redirect?view=aspnet-mvc-5.2
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, January 8, 2019 9:15 PM
All replies
-
User475983607 posted
I assume you forgot to add the antiforgery token to the HTML form within the View.
Tuesday, January 8, 2019 6:15 PM -
User-1664485818 posted
Thanks, I have now added the following code to the view;
@Html.AntiForgeryToken()
Now receiving this error;
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: Server cannot append header after HTTP headers have been sent. occurredTuesday, January 8, 2019 7:31 PM -
User475983607 posted
Thanks, I have now added the following code to the view;
@Html.AntiForgeryToken()
Now receiving this error;
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: Server cannot append header after HTTP headers have been sent. occurredThe construct in MVC is to return a Redirect.
return Redirect("https://www.google.com");
Tuesday, January 8, 2019 7:49 PM -
User-1664485818 posted
I added the code
return Redirect("https://www.google.com");
but, now receiving this error;
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (:).
Tuesday, January 8, 2019 7:57 PM -
User475983607 posted
Redirect has always worked. The error message is related to the client making a request to your site not redirecting to google. I assume the error is not related to return Redirect but a bug in your code base.
Please take a moment to review and debug your code. If you need help troubleshooting your code then post enough code so we can reproduce the issue.
Tuesday, January 8, 2019 8:18 PM -
User-1664485818 posted
This is the url when the application fails
http://localhost:56973/umbraco/Surface/RegisterNewUser/https%3a/google.com
return RedirectToAction("https://google.com");
Tuesday, January 8, 2019 8:36 PM -
User475983607 posted
This is the url when the application fails
http://localhost:56973/umbraco/Surface/RegisterNewUser/https%3a/google.com
return RedirectToAction("https://google.com");
Of course it fails and of course the Google URL is appended to the URL as that's how RedirectToAction works.
Use...
return Redirect("https://www.google.com");
...when redirecting outside the current application or to a specific URL.
https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.redirect?view=aspnet-mvc-5.2
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, January 8, 2019 9:15 PM -
User-1664485818 posted
Thank you, I owe you a beer or 2 much appreciated :)
Tuesday, January 8, 2019 9:25 PM