Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The localhost page isn’t working. localhost redirected you too many times

I got a problem when debugging my MVC program and I want to acces to my db called "UserActivity". on the browser, it saying that "The localhost page isn’t working

localhost redirected you too many times."

but without showing the specific error location.

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);
    }
}

Really appreciate if there anyone who know something about this problem. Thanks

like image 733
Botski Avatar asked Mar 17 '16 08:03

Botski


People also ask

How do I fix redirected you too many times?

Microsoft Edge states that the domain redirected you too many times and suggests clearing the cookies to fix the issue. Most browsers suggest that cookies might be the reason for the ERR_TOO_MANY_REDIRECTS error.

What causes too many redirects?

The reason you see the “too many redirects” error is because your website has been set up in a way that keeps redirecting it between different web addresses. When your browser tries to load your site, it goes back and forth between those web addresses in a way that will never complete — a redirect loop.

What does redirected you too many times mean?

What does the ERR_TOO_MANY_REDIRECTS mean? The error too many redirects is shown when the browser can't establish a connection between the initial page and the destination page in a redirect. If you use Google Chrome, the warning looks like this: “This page isn't working.

How do you fix too many redirects Chrome?

Too Many Redirects as a Visitor Open Chrome and select the Chrome pull-down menu at the top. Next, select More tools > Clear browsing data… from the pull-down menu, you can also type Ctrl+Shift+Del to open the window in the next step. Now, click the checkbox next to Cached images and files. Then, click Clear data.


2 Answers

if (userActivity != null)
{
    return RedirectToAction(returnUrl);
}

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

like image 157
Lesmian Avatar answered Nov 15 '22 09:11

Lesmian


You have a loop back situation. This is similar to endless while loop. To fix it change your code redirection implementation to redirect to an action method. Notice how I have changed the implementation below. This will fix the issue "localhost redirected you too many times". You can improve on it to support passing in parameters, etc suitable for your situation. Also take a look at RedirectToAction with support for additional parameters, if you want to pass parameters to the 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();
        }
   }
like image 28
Julius Depulla Avatar answered Nov 15 '22 09:11

Julius Depulla