2

This is my main layout of the application

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Date Picker", "Index", "Home", null, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")

            </div>
        </div>
    </div>

    @if (User.Identity.IsAuthenticated)
    {
        <div class="row">
            <div class="col-md-3">
                <div class="bs-sidebar hidden-print affix" role="complementary">
                    <ul class="nav bs-sidenav">                       
                        <li class="active">
                            @Html.ActionLink("Address Book","Index","AddressBook")
                            <ul class="nav">                              
                                <li>
                                    @Html.ActionLink("Add Contact", "AddPerson", "AddressBook")
                                </li>                               
                            </ul>
                        </li>
                        <li>
                            @Html.ActionLink("App", "Create", "Appointment")                           
                        </li>
                        <li>
                            @Html.ActionLink("myconn", "Index", "Connection")//error when I click this link.                     
                        </li>
                    </ul>
                </div>
            </div>
        </div>      
    }
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - MyApp</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

I get the sidebar when the user is logged in, all the links work in sidebar except

@Html.ActionLink("myconn", "Action", "Controller")   

When I click the link called SuperOffice browser link changes to http://localhost:14834/Connection but I get error: in visual studio saying

An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll

Here is my controller code

[Authorize]
public class Controller : Controller
{
    private readonly IConnectionRepository _connectionRepository;

    public ConnectionController(IConnectionRepository connectionRepository)
    {
        _connectionRepository = connectionRepository;
    }
}

When I put breakpoint in Index method of Connection controller, and click the SuperOffice link, I don't even get to that method. Any idea what is happening? I find it strange that all the link are working and I get forwarded to controller and all thing works perfect except that one.

10
  • 1
    Put a breakpoint in the class constructor, there's some circular reference somewhere in your code. Commented Jan 30, 2014 at 13:29
  • my controller class or repository class? Commented Jan 30, 2014 at 13:33
  • your controller class Commented Jan 30, 2014 at 13:37
  • @JeremyHolovacs i never get forwarded to that controller, application breaks when I click that link in browser. I have break point at the first line of that class but never gets called Commented Jan 30, 2014 at 13:43
  • 1
    Your account controller class should not have the Authorized attribute. Try removing that and see if that makes a difference. Commented Jan 30, 2014 at 14:00

2 Answers 2

1

You probably have [Authorize] attribute somewhere that is giving you stackoverflow.

Sign up to request clarification or add additional context in comments.

1 Comment

No, It came from my repository, apparently I cannot have two repositories, instantiating each other at constructor.
0
    var hasSuperOfficeConnection = _connectionRepository.CheckIfSuperOfficeIsConnected(userId);
    var model = new Index
    {
        IsSuperOfficeConnected = hasSuperOfficeConnection
    };

I think there is a infinite loop here If you can give more code (ie IsSuperOficeConnected) we can help you more

public class ConnectionRepository:IConnectionRepository
{
    private readonly DatePickerDbContext _db;
    //private readonly ISuperOfficeRepository _superOfficeRepository;

    public ConnectionRepository(DatePickerDbContext db)//, ISuperOfficeRepository superOfficeRepository
    {
        _db = db;
      //  _superOfficeRepository = superOfficeRepository;
    }
     public int GetConnectionId(string connectionName)
     {
        var connection = _db.Connections.Single(c => c.Name == connectionName);
        return connection.Id;
      }

     public bool CheckIfSuperOfficeIsConnected(string userId)
     {
        var connectionId = GetConnectionId("SuperOffice");
        var result = _db.UserConnections.Where(uc => uc.UserId == userId && uc.ConnectionId == connectionId);
        return result.Any();
     }
 }

4 Comments

_connectionRepository calls _superOfficeRepository and _superOfficeRepository calls _connectionRepository that causes infinite loop
do you need superOfficeRepository in ConnectionRepository? if not just delete it and probably problem will be fixed
Actually I need it. but may be I can just merge them
where do you use superOfficeRepository? Not seen in given code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.