这是我应用程序的主要布局
<!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>© @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
但我得到错误:在视觉工作室说
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;
}
}
当我在Connection控制器的Index方法中放置断点,并单击SuperOffice链接时,我甚至没有使用该方法。 知道发生了什么吗? 我觉得很奇怪,所有的链接都在工作,我被转发到控制器,除了那个之外,所有的东西都很完美。
答案 0 :(得分:0)
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();
}
}
答案 1 :(得分:0)
你可能在某个地方有[Authorize]
属性,它给你stackoverflow。