- Global.asax - WindowsAuthentication_Authenticate - SessionState null and Multiple Calls
- <link href="@Url.Stylesheet("Common.css")" rel="stylesheet" type="text/css" />
- <script src="@Url.Script("Tools/extensions.js")" type="text/javascript"></script>
- protected void WindowsAuthentication_Authenticate(object sender, WindowsAuthenticationEventArgs e)
- {
- bool isUserFound = false;
- bool isUserGone = false;
- UtilityService utility = new UtilityService();
- string rawurl = HttpContext.Current.Request.RawUrl;
- if (e.Identity.IsAuthenticated)
- {
- if (userPlaceHolder == null) //local property, work around for session problem
- {
- UserInternal userInternal = utility.GetLoggedInUser(e.Identity.Name);
- if (userInternal != null)
- {
- userPlaceHolder = userInternal;
- isUserFound = true;
- //TODO: check for gone, you can use userInternal or userPlaceHolder
- isUserGone = false;
- }
- }
- else
- {
- isUserFound = true;
- //TODO: check for gone, use userPlaceHolder
- isUserGone = false;
- }
- }
- //set the user
- if (isUserFound && !isUserGone)
- {
- string role = String.IsNullOrWhiteSpace(userPlaceHolder.UserClass) ? String.Empty : userPlaceHolder.UserClass;
- // Setting the current user and role in the Principal
- e.User = new System.Security.Principal.GenericPrincipal(e.Identity, new string[] { role });
- HttpContext.Current.User = e.User;
- }
- //handle gone and user not found
- if (!rawurl.LowerInvariantContains(ControllerNames.Message) &&
- !rawurl.LowerInvariantContains(".css") &&
- !rawurl.LowerInvariantContains(".js") &&
- !rawurl.LowerInvariantContains(".jpg") &&
- !rawurl.LowerInvariantContains(".gif") &&
- !rawurl.LowerInvariantContains(".png"))
- {
- if (!isUserFound || isUserGone)
- {
- string url = String.Empty;
- if (isUserGone)
- url = utility.GetSiteRestrictedLink(ProcessingMessagesEnum.UserLocked);
- else
- url = utility.GetSiteRestrictedLink(ProcessingMessagesEnum.UserNotAuthorizedToViewSite); ;
- HttpContext.Current.Response.Redirect(url);
- }
- }
- }