The localhost site is down. localhost redirected you too many times

I am having trouble debugging my MVC program and I want to access my db called "UserActivity". in the browser it says that the "localhost page is not working

localhost redirected you too many times.

but without specifying the specific location of the error.

here is my UserActivtyController, GET / UserActivity / Index code:

public class UserActivityController : BaseController { //GET /UserActivity/Index public ActionResult Index(string returnUrl, int page = 1, string sort = "Id", string sortDir = "ASC", string filter = null) { String query = @" SELECT Id ,CreatedBy ,CreatedOn ,ModifiedBy ,ModifiedOn ,ContactId ,EntityName ,EntityId ,ActivityType ,ActivityStatus ,DueDate ,ActualEndDate ,MasqueradeOn ,MasqueradeBy FROM UserActivity -- ORDER BY CreatedOn DESC -- OFFSET (@PageNumber -1) * 30 ROWS -- FETCH NEXT 30 ROWS ONLY "; //string countQuery = @"" List<UserActivityModels> userActivity = null; using (IDbConnection db = new MySqlConnection(ConfigurationManager.ConnectionStrings["CRMPORTALSQLCONN"].ConnectionString)) { userActivity = (List<UserActivityModels>)db.Query<UserActivityModels>(query, new { @PageNumber = page, }); /*ViewData["TotalCount"] = (int)db.ExecuteScalar(countQuery, new { @PageNumber = page, @Id = string.IsNullOrEmpty(filter) ? null : filter }); */ ViewData["PageSize"] = 30; ViewData["Filter"] = filter; } if (userActivity != null) { return RedirectToAction(returnUrl); } return View(userActivity); } } 

Do evaluate if there is anyone who knows something about this issue. Thanks

+5
source share
3 answers
 if (userActivity != null) { return RedirectToAction(returnUrl); } 

If returnUrl points to the same action ("UserActivity / Index"), it will create an infinite redirect loop. If you want to redirect the request to different actions, make sure that you pass the correct name.

+4
source

You have a feedback situation. This is like an endless while loop. To fix this, change the code forwarding implementation to redirect to the action method. Notice how I changed the implementation below. This will fix the problem "localhost redirected you too many times." You can improve it to support passing parameters, etc., Suitable for your situation. Also look at RedirectToAction with support for additional parameters, if you want to pass parameters to an action method, this link will be useful.

  public class UserActivityController : BaseController { //GET /UserActivity/Index public ActionResult Index(int page = 1, string sort = "Id", string sortDir = "ASC", string filter = null) { // Your other implementation here. I have removed it for brevity. if (userActivity != null) { return RedirectToAction("Index"); } return View(userActivity); } public ActionResult Index() { return View(); } } 
+1
source

I do not know what redirectUrl , but I assume that it is null. I also assume that your userActivity not null . So, return RedirectToAction(returnUrl); called out.

When you call RedirectToAction(null) , you are actually redirected to the same action, and everything repeats again.

I am also wondering why you need return View(userActivity); when your userActivity is null . I assume you have a logical error.

0
source

Source: https://habr.com/ru/post/1245218/


All Articles