首页 > 解决方案 > 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?

标签: c#asp.net-mvc-5routes

解决方案


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.


推荐阅读