Context.User.Identity.Name是什麼意思?

來源:互聯網
上載者:User

 

在ASP.NET中有三種身分識別驗證方式。當使用其中的一種來驗證目前使用者並通過時,必然要在伺服器及用戶端之間儲存一種驗證票據來儲存驗證資訊。.NET提供類似於IIdentity的介面來完成該功能。請樓主注意,context.user是IPrincipal類型介面,而identity是IIdentity類型的介面。有四種類FormsIdentity GenericIdentity PassportIdentity WindowsIdentity實現了IIdentity介面。這幾種類對應於.NET的幾種驗證模式。以上也差不多是廢話,只是說了一下。
不過,請樓主看一下以上說的, 再對MSDN裡尋找一下ASP.NET的Forms驗證的文章。看一下在forms驗證時對FormsIdentity類的使用,有些資訊儲存到FormsIdentity類的執行個體裡,在使用的時候就可以context.user.identity.name提取出來。

 

 

 

你可以這樣寫:  

  在登入頁面上:  

 密碼驗證通過後:FormsAuthentication.RedirectFromLoginPage(yourname.Text,false); 

  在定向到的頁面上:  

  string   getname  =   User.Identity.Name;

你看看SDK關於安全性--"基於表單的身分識別驗證"的例子,會有協助. 

 要想將Session賦值給User.Identity.Name,可以在登陸頁將Number.Text賦值給Session。

 哈哈,關於安全方面的一個問題。  

 你可以用自己的類放到user.Identity中。Context.User.Identity.Name的意思是目前使用者的名字。可以放你任何想要的東西。不過放的時候要注意,可以用一下代碼: 

  HttpContext.Current.User   =  new   GenericPrincipal(object,  “”);  

  object是你自己定義的類。

__________________________________

  查看文章    
Context.User.Identity.Name說明2009-05-14 21:46

//感謝百度,感謝我的hy導師,感謝各位師兄師弟師姐師妹,感謝毛主席,感謝基督耶穌,感謝默罕默德,感謝和諧

    今天做了一個身分識別驗證頁面,基本實現功能,卻不能顯示目前使用者姓名,自己MSDN半天一無所獲,問題就在Context.User.Identity.Name;Context是HttpContext類,User屬性Gets or sets security information for the current HTTP request,再查identity是IIdentity類型的介面;Name是它的Public Properties,可以Gets
the name of the current user。依舊木有辦法。網上的大蝦們說是驗證方式的問題,就知道Form方式,加到Web.cofig裡,直接搞定!!!!

////////////////////////////粘網路資源,共用快樂

(1)在ASP.NET中有三種身分識別驗證方式。當使用其中的一種來驗證目前使用者並通過時,必然要在伺服器及用戶端之間儲存一種驗證票據來儲存驗證資訊。.NET提供類似於IIdentity的介面來完成該功能。請樓主注意,context.user是IPrincipal類型介面,而identity是IIdentity類型的介面。有四種類FormsIdentity GenericIdentity PassportIdentity
WindowsIdentity
實現了IIdentity介面。這幾種類對應於.NET的幾種驗證模式。以上也差不多是廢話,只是說了一下。 不過,請樓主看一下以上說的, 再對MSDN裡尋找一下ASP.NET的Forms驗證的文章。看一下在forms驗證時對FormsIdentity類的使用,有些資訊儲存到FormsIdentity類的執行個體裡,在使用的時候就可以context.user.identity.name提取出來。

(2)Context.User.Identity.Name總是為空白,望高手指教為什嗎?
______________________________________________________________________________________________
答1:
are you using forms-based authentication or windows integrated authentication?
______________________________________________________________________________________________
答2:
你把asp.net改為windows內建驗證,Context.User.Identity.Name就有值了
______________________________________________________________________________________________
答3:
up

附上:Web.config//只解決本問題,其他問題再說

<system.web>
      <authentication mode = "Forms">

</system.web>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.