Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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