隐藏超链接的特定用户名或 ID ASP.Net
Specific Username or ID to hide hyperlink ASP.Net
我目前将会话设置为在用户登录或未登录时显示某些超链接。有没有办法针对特定的用户名或 ID 执行此操作?
目前我的会话代码是这样的-
@if (Session["UsernameSS"] != null)
{
<td>
@Html.ActionLink("Add Thing", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
}
else
{
<td>
@Html.ActionLink("Details", "Details", new { id = item.ID })
</td>
}
有没有办法编码,这样@if (Session["UsernameSS"] == "John Doe"
只有他才能看到某个超链接?
感谢任何帮助,谢谢!
是的,您可以将 Session
变量转换为字符串(在本例中),然后进行比较:
@if (Session["UsernameSS"] != null)
{
if(Convert.ToString(Session["UsernameSS"]) == "John Doe")
{
<!-- Show these links to John Doe ONLY -->
<td>
@Html.ActionLink("Add Thing", "Edit", new { id = item.ID }) |
</td>
}
else
{
<!-- Show these links to everyone else -->
<td>
@Html.ActionLink("Add Thing", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
}
}
else
{
<td>
@Html.ActionLink("Details", "Details", new { id = item.ID })
</td>
}
我目前将会话设置为在用户登录或未登录时显示某些超链接。有没有办法针对特定的用户名或 ID 执行此操作?
目前我的会话代码是这样的-
@if (Session["UsernameSS"] != null)
{
<td>
@Html.ActionLink("Add Thing", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
}
else
{
<td>
@Html.ActionLink("Details", "Details", new { id = item.ID })
</td>
}
有没有办法编码,这样@if (Session["UsernameSS"] == "John Doe"
只有他才能看到某个超链接?
感谢任何帮助,谢谢!
是的,您可以将 Session
变量转换为字符串(在本例中),然后进行比较:
@if (Session["UsernameSS"] != null)
{
if(Convert.ToString(Session["UsernameSS"]) == "John Doe")
{
<!-- Show these links to John Doe ONLY -->
<td>
@Html.ActionLink("Add Thing", "Edit", new { id = item.ID }) |
</td>
}
else
{
<!-- Show these links to everyone else -->
<td>
@Html.ActionLink("Add Thing", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
}
}
else
{
<td>
@Html.ActionLink("Details", "Details", new { id = item.ID })
</td>
}