2009-08-26 62 views

回答

71

這是行不通的嗎?

<%= Page.User.Identity.IsAuthenticated %> 
+5

或者試試'<%= Context.User.Identity.IsAuthenticated%>' – 2015-05-04 22:45:29

70

沒有新添加到Griegs答案,但我通常會做

@Request.IsAuthenticated 
+3

在參考來源尋找'HttpRequestWrapper'然後'HttpRequest'了'IsAuthenticated'財產用'User.Identity.IsAuthenticated'實現,除此之外。 'return(_context.User!= null && _context.User.Identity!= null && _context.User.Identity.IsAuthenticated);' – 2013-07-07 08:18:46

+1

那麼有什麼區別?或者這兩個相同? – 2016-01-09 16:06:55

+0

非常。礦井較短。 :-) – 2016-01-10 00:07:57

9

你可以裝飾與Authorize屬性的方法。這要求調用方法的用戶進行身份驗證。

0

嗯,我用VB

If User.Identity.Name = "" Then 
    Response.Redirect("~/Login.aspx") 
Else 
    ........continue........... 
End If 
+0

由於原始問題無法訪問'用戶',這將如何在用戶控制中產生任何影響「。你的例子是在控制器中,而不是用戶控制。 -1 – 2015-07-24 11:40:28