Solved

Global.asax Redirect is removing CSS and producing Java script error as "syntax error code 0"

Posted on 2011-03-08
5
819 Views
Last Modified: 2012-05-11
Hi

I have the code below to in the global.asax to redirect users to the change password page when its been 48 since they last cahnged thir passowrd


 
Sub Application_PostAuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        'code that runs after the person has been authicated
        If User.Identity.IsAuthenticated Then
 
              Dim userdetails As MembershipUser = Membership.GetUser
            ' If userdetails.LastPasswordChangedDate < Today.AddDays(-48) Then
            If Request.RawUrl.Contains("/Account/ChangePassword.aspx") = False Then

                Response.Redirect("~/Account/ChangePassword.aspx")
            End If
        'End If
        End If
    End Sub

Open in new window


The problem is that when this redirect is triggered the change password page loads without any css styling and with 2 "syntax errors code 0" in IE.

going to the change passowrd page normally or from redirects from other pages, it all loads fine.

the problem is just when loading via a redirect from the global.asax

Any ideas what to look for.
0
Comment
Question by:bolt81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35068128
I would guess it is an issue with performing a redirect when either WebResource.axd or ScriptResource.axd are triggering the PostAuthenticationRequest handler. Try changing your code to:
Sub Application_PostAuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
    If TypeOf(context.Handler) Is IRequiresSessionState Or TypeOf(context.Handler) Is IReadOnlySessionState Then

        'code that runs after the person has been authicated
        If User.Identity.IsAuthenticated Then
 
              Dim userdetails As MembershipUser = Membership.GetUser
            ' If userdetails.LastPasswordChangedDate < Today.AddDays(-48) Then
            If Request.RawUrl.Contains("/Account/ChangePassword.aspx") = False Then

                Response.Redirect("~/Account/ChangePassword.aspx")
            End If
        'End If
        End If

    End If
End Sub

Open in new window

0
 
LVL 2

Expert Comment

by:rahulbagal
ID: 35068143
I would suggest instead of redirecting the user from global.asax  you can set a flag there & do redirection in page load of other pages .

0
 
LVL 1

Author Comment

by:bolt81
ID: 35068356
I've added the above code and it stopped the redirect happening altogether.

i want to do it in the global so that users are redirected no matter what page they go to.

I could  place a piece of code at the top of each page to handle this, but isn't this the idea of the global.asax?

If anyone has a alternative way to do this i'm all ears

thanks
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35068484
The problem is that that event doesn't just fire for pages, it also fires for other resources which you need to exclude. You could try the more "sledgehammer" approach of:
Sub Application_PostAuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)

        'code that runs after the person has been authicated
        If User.Identity.IsAuthenticated Then
 
              Dim userdetails As MembershipUser = Membership.GetUser
            ' If userdetails.LastPasswordChangedDate < Today.AddDays(-48) Then
            If Request.RawUrl.Contains("/Account/ChangePassword.aspx") = False And Request.RawUrl.Contains(".axd") = False Then

                Response.Redirect("~/Account/ChangePassword.aspx")
            End If
        'End If
        End If

End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:bolt81
ID: 35068659
That fixed it, This stopped the javascript errors.

i added "And Request.RawUrl.Contains(".css") = False", which stopped the issue with the css not running as well
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question