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 replaceResponse.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();
}
}
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. occurred
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. occurred
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.
Member
256 Points
732 Posts
Response.Redirect
Jan 08, 2019 05:10 PM|brucey|LINK
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 :)
All-Star
52091 Points
23212 Posts
Re: Response.Redirect
Jan 08, 2019 06:15 PM|mgebhard|LINK
I assume you forgot to add the antiforgery token to the HTML form within the View.
Member
256 Points
732 Posts
Re: Response.Redirect
Jan 08, 2019 07:31 PM|brucey|LINK
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. occurred
All-Star
52091 Points
23212 Posts
Re: Response.Redirect
Jan 08, 2019 07:49 PM|mgebhard|LINK
The construct in MVC is to return a Redirect.
Member
256 Points
732 Posts
Re: Response.Redirect
Jan 08, 2019 07:57 PM|brucey|LINK
I added the code
but, now receiving this error;
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (:).
All-Star
52091 Points
23212 Posts
Re: Response.Redirect
Jan 08, 2019 08:18 PM|mgebhard|LINK
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.
Member
256 Points
732 Posts
Re: Response.Redirect
Jan 08, 2019 08:36 PM|brucey|LINK
This is the url when the application fails
http://localhost:56973/umbraco/Surface/RegisterNewUser/https%3a/google.com
All-Star
52091 Points
23212 Posts
Re: Response.Redirect
Jan 08, 2019 09:15 PM|mgebhard|LINK
Of course it fails and of course the Google URL is appended to the URL as that's how RedirectToAction works.
Use...
...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
Member
256 Points
732 Posts
Re: Response.Redirect
Jan 08, 2019 09:25 PM|brucey|LINK
Thank you, I owe you a beer or 2 much appreciated :)