Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. @using System.Security.Claims;
  2. @{
  3.  
  4. Microsoft.Owin.IOwinContext ctx = Request.GetOwinContext();
  5. var usr = Request["text1"];
  6. if (IsPost && usr == "valid@user.com")
  7. {
  8. ctx.Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);
  9.  
  10. var claims = new List<Claim>();
  11. claims.Add(new Claim(ClaimTypes.Email, usr));
  12. claims.Add(new Claim(ClaimTypes.Name, var));
  13. var id = new ClaimsIdentity(claims, Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);
  14. ctx.Authentication.SignIn(id);
  15. //FormsAuthentication.SetAuthCookie("valid@user.com", false); // Also fails
  16. }
  17. var IP = HttpContext.Current.User.Identity.IsAuthenticated.ToString();
  18. var text = "valid@user.com";
  19.  
  20. }
  21. <!DOCTYPE html>
  22. <html lang="en">
  23. <head><title></title></head>
  24. <body>
  25. <p>Are we Logged in? <strong>@IP</strong>.</p>
  26. <form action="" method="post">
  27. <p>
  28. <label for="text1">First Number:</label>
  29. <input type="text" name="text1" value="@text" />
  30. <p><input type="submit" value="Add" /></p>
  31. </form>
  32. </body>
  33. </html>
  34.  
  35. using Microsoft.AspNet.Identity;
  36. using Microsoft.Owin;
  37. using Microsoft.Owin.Security;
  38. using Microsoft.Owin.Security.Cookies;
  39. using Owin;
  40.  
  41. [assembly: OwinStartup(typeof(TypeScriptHTMLApp1.Startup1))]
  42.  
  43. namespace TypeScriptHTMLApp1
  44. {
  45. public class Startup1
  46. {
  47. public void Configuration(IAppBuilder app)
  48. {
  49. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
  50. app.UseCookieAuthentication(new CookieAuthenticationOptions
  51. {
  52. AuthenticationType =DefaultAuthenticationTypes.ApplicationCookie,
  53. AuthenticationMode = AuthenticationMode.Passive,
  54. });
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement