PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/Microsoft.AspNet.SignalR.Hosting.AspNet.Samples/Hubs/Auth/Default.aspx.cs

https://github.com/mip1983/SignalR
C# | 35 lines | 32 code | 3 blank | 0 comment | 1 complexity | 992c2ba6d56f57fdaa3dbf059fd6785a MD5 | raw file
Possible License(s): Apache-2.0, CC-BY-SA-3.0
  1. using System;
  2. using System.Linq;
  3. using System.Security.Principal;
  4. using System.Web.Security;
  5. using System.Web.UI;
  6. namespace Microsoft.AspNet.SignalR.Hosting.AspNet.Samples.Hubs.Auth
  7. {
  8. public partial class _Default : Page
  9. {
  10. protected void Login(object sender, EventArgs e)
  11. {
  12. var userId = Guid.NewGuid().ToString();
  13. FormsAuthentication.SetAuthCookie(userId, createPersistentCookie: false);
  14. var identity = new GenericIdentity(userName.Text);
  15. var principal = new GenericPrincipal(identity, SplitString(roles.Text));
  16. Context.User = principal;
  17. Cache[userId] = principal;
  18. }
  19. private static string[] SplitString(string original)
  20. {
  21. if (String.IsNullOrEmpty(original))
  22. {
  23. return new string[0];
  24. }
  25. var split = from piece in original.Split(',')
  26. let trimmed = piece.Trim()
  27. where !String.IsNullOrEmpty(trimmed)
  28. select trimmed;
  29. return split.ToArray();
  30. }
  31. }
  32. }