gpt4 book ai didi

c# - MVC : An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll

转载 作者:行者123 更新时间:2023-12-02 10:46:56 25 4
gpt4 key购买 nike

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

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

这是我的 Controller 代码
[Authorize]
public class Controller : Controller
{
private readonly IConnectionRepository _connectionRepository;

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

当我在Connection controller的Index方法中放置断点,然后单击SuperOffice链接时,我什至不知道该方法。
知道发生了什么吗?
我发现所有链接都正常工作,这很奇怪,我被转发到 Controller ,除那个链接外,其他所有东西都运行良好。

最佳答案

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

我认为这里存在无限循环如果您可以提供更多代码(即IsSuperOficeConnected),我们可以为您提供更多帮助
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();
}
}

关于c# - MVC : An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21457730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com