[英]redirect page on specific user detection asp.net
我想如何在asp.net中實現以下功能:
我具有Windows身份驗證,我希望服務器檢測用戶是誰,並根據頁面上的用戶名重定向頁面。
是否有捷徑可尋?
您可以獲取用戶名,例如...
string username = HttpContext.Current.User.Identity.Name.ToString();
擁有用戶名后,您可以將頁面重定向到特定頁面。
編輯:您可以在Application_AuthenticateRequest
事件(即Global.asax
文件)中進行操作
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
// put code here....
}
}
對於事件,這取決於您的代碼。 我認為如果您有任何疑問,可以在page_load事件中執行此類操作,您應該檢查ASP.NETlifecylce http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=asp.net+lifecycle
順便說一句,您可以使用Response.redirect來重定向用戶。
非常簡單
protected void Page_Load(object sender, EventArgs e)
{
string username = HttpContext.Current.User.Identity.Name.ToString();
if (username == "someusername")
{
Response.Redirect("someaspxfile.aspx");
}
}
如果您要獲取帶有用戶名的控件,它將在請求中可用。 您可以從請求中選擇數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.