我目前設定了會話以在用戶登錄或未登錄時顯示某些超鏈接。有沒有辦法針對特定的用戶名或 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" 那么只有他可以看到某個超鏈接?
任何幫助表示贊賞,謝謝!
uj5u.com熱心網友回復:
是的,您可以將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>
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/473007.html
