c# - RedirectToAction appends route to URL instead of directing to action in other controller
问题描述
I have a simple RedirectToAction
at the end of a controller method in the controller "AccountController". I want to redirect now to a method called loads
in the Home
controller. Code:
return RedirectToAction("loads", "Home", new { unique_id = new_questionnaire.Unique_ID, purpose = "resume" });
Instead of going to http://localhost:40829/Home/loads/...
, it goes to http://localhost:40829/Home/Index?ReturnUrl=%2fHome%2floads%3funique_id%3d49557%26purpose%3dresume&unique_id=49557&purpose=resume
. What am I doing wrong here? How can I redirect to another controller method while passing route values as well?
解决方案
The problem was that I use Forms Authentication and the user was not authenticated when trying to access the URL. This caused the website to redirect the user to the login page.
When ReturnURL
shows up in the url, this might be the problem. Hope this can help people in the future.
In my case, adding a Cookie
and a Forms Authentication Ticket
solved the problem. I already had a function ready for this, I just needed to call it.
推荐阅读
- curl - 设置变量等于范围内的模式匹配
- android - java.lang.IllegalStateException:应为 BEGIN_OBJECT 但在第 2 行第 1 列错误为 STRING
- bash - 在 Bash 中:grep 命令输出未存储在文件中,并将其存储在文件中?
- scipy - 简单的 scipy curve_fit 测试未返回预期结果
- javascript - 如何在项目数组中选择一个按钮并取消选择前一个值
- python - SQLAlchemy 的“post_update”与已从会话中删除的对象的行为不同
- node.js - npm - 更新 @angular/cli 后如何修复错误代码 ELIFECYCLE
- java - Wire concrete implementation to interface in blueprint.xml
- node.js - nodejs request.body 没有显示任何参数
- jenkins - 如何在 Jenkinsfile 中获取项目类型详细信息?