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
Solved

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

Posted on 2011-03-08
5
809 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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