我在ASP.Net中使用內置身份驗證。 我想讓它在用戶註冊時自動添加到我創建的角色中。我該怎麼做呢?ASP.Net中的默認角色內置身份驗證
0
A
回答
1
我假設你使用默認的Asp.Net成員和角色提供者。如果你使用CreateUserWizard
,在OnCreatedUser
處理程序,你可以簡單地執行這樣的事情:
string userName = Membership.GetUser().UserName;
Roles.AddUserToRole(userName, "<role>");
0
使用這樣的:
string user ="";
user = RegisterUser.UserName.ToString();
Roles.AddUserToRole(user, "Employee");
例如:
protected void RegisterUser_CreatedUser(object sender, EventArgs e)
{
FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);
string continueUrl = RegisterUser.ContinueDestinationPageUrl;
if (!OpenAuth.IsLocalUrl(continueUrl))
{
continueUrl = "~/";
}
string user ="";
user = RegisterUser.UserName.ToString();
Roles.AddUserToRole(user, "Employee");
Response.Redirect(continueUrl);
}
+0
如果你也解釋它是如何工作的以及你爲什麼這樣做,這可能是有用的。 –
+0
它只是工作很好....我沒有發明Asp.net,所以只需遵循使用asp.net和visual studio的發明者的規則希望我們的開發人員遵循,這就是爲什麼 – Monir
+0
我們會從你學到更多if你評論了你遵循的規則:-) –
相關問題
- 1. 基於角色的身份驗證與asp.net中的窗口身份驗證
- 2. Windows身份驗證角色
- 3. ASP.NET成員身份角色和身份驗證的缺點?
- 4. Windows身份驗證不驗證角色
- 5. WPF中的身份驗證和角色
- 6. ASP .NET Core Identity默認身份驗證與JWT身份驗證
- 7. 在asp.net窗體身份驗證動態設置默認網址
- 8. 基於角色的身份驗證
- 9. 開發驗證的身份和角色
- 10. 從webview默認身份驗證
- 11. Laravel默認身份驗證與模式
- 12. SQL Windows身份驗證角色?
- 13. socket.io連接角色身份驗證
- 14. 使用窗體身份驗證cookie中緩存角色 - (Windows身份驗證)
- 15. ASP.NET身份驗證與靜態內容IIS7中的角色集成模式
- 16. 要求登錄默認頁面的ASP.NET身份驗證
- 17. asp.net,未通過表單身份驗證分配的角色
- 18. 使用Cookie和無SQL的ASP.NET MVC3角色身份驗證?
- 19. 沒有提供商的Asp.Net MVC身份驗證角色
- 20. 使用Windows身份驗證的ASP.NET角色管理
- 21. 角色的身份驗證是不是在asp.net
- 22. 基於ASP.Net角色的表單身份驗證
- 23. ASP.NET身份驗證
- 24. ASP.net身份驗證
- 25. ASP.NET身份驗證
- 26. 如何在Firebase身份驗證中設置角色?
- 27. ASP.NET成員身份角色Web.config設置
- 28. asp.net mvc修改默認身份驗證系統
- 29. ASP.NET MVC和Windows身份驗證與自定義角色
- 30. ASP.NET Windows身份驗證與自定義角色
我知道這是舊的,但我們都同意顯示導入的命名空間?使用System.Web.Security。 – kerbasaurus