-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.asax.cs
88 lines (69 loc) · 3.21 KB
/
Global.asax.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Script.Serialization;
using System.Web.Security;
using Moto.App_Start;
using moto.Models;
namespace moto
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
JavaScriptSerializer serializer = new JavaScriptSerializer();
CustomPrincipalSerializeModel serializeModel = serializer.Deserialize<CustomPrincipalSerializeModel>(authTicket.UserData);
CustomPrincipal newUser = new CustomPrincipal(authTicket.Name);
////newUser.UserGuid = serializeModel.UserGuid;
////newUser.FirstName = serializeModel.FirstName;
////newUser.LastName = serializeModel.LastName;
//newUser.UserGuid = Guid.Parse("67C919E2-8DF4-476A-B312-C26F82A36CFB");
//newUser.FirstName = "Can";
//newUser.LastName = "Akcan";
HttpContext.Current.User = newUser;
}
}
protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
JavaScriptSerializer serializer = new JavaScriptSerializer();
CustomPrincipalSerializeModel serializeModel = serializer.Deserialize<CustomPrincipalSerializeModel>(authTicket.UserData);
CustomPrincipal newUser = new CustomPrincipal(authTicket.Name);
//newUser.UserGuid = serializeModel.UserGuid;
//newUser.FirstName = serializeModel.FirstName;
//newUser.LastName = serializeModel.LastName;
using (KrankEntities ent = new KrankEntities())
{
//User.Identity.Name
Guid userGuid = Guid.Parse(User.Identity.Name);
aspnet_Users user= ent.aspnet_Users.First(i => i.UserId ==userGuid );
newUser.UserGuid = user.UserId;
newUser.FirstName = "Can";
newUser.LastName = "Akcan";
}
//newUser.UserGuid = Guid.Parse("67C919E2-8DF4-476A-B312-C26F82A36CFB");
//newUser.FirstName = "Can";
//newUser.LastName = "Akcan";
HttpContext.Current.User = newUser;
}
}
}
}