MVC:System.Core 中发生了 'System.StackOverflowException' 类型的未处理异常.dll



这是我应用程序的主要布局

<!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>

我在用户登录时获取侧边栏,所有链接在侧边栏中都可以使用

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

单击链接时,称为SuperOffice浏览器链接更改为http://localhost:14834/Connection但是我遇到了错误:在Visual Studio中说

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

这是我的控制器代码

[Authorize]
public class Controller : Controller
{
    private readonly IConnectionRepository _connectionRepository;
    public ConnectionController(IConnectionRepository connectionRepository)
    {
        _connectionRepository = connectionRepository;
    }
}

当我将Breakpoint放入连接控制器的索引方法中,然后单击Superoffice链接时,我什至不使用该方法。知道发生了什么事吗?我发现所有链接都在工作,我被转发到控制器很奇怪,除了一个。

您可能有[Authorize]属性在给您堆叠的地方。

    var hasSuperOfficeConnection = _connectionRepository.CheckIfSuperOfficeIsConnected(userId);
    var model = new Index
    {
        IsSuperOfficeConnected = hasSuperOfficeConnection
    };

我认为,如果您可以提供更多代码(即iSsuperoficeContected),这里有一个无限的循环,我们可以帮助您更多

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

相关内容

最新更新