Bad Data Error

G

Guest

I downloaded the Portal Starter Kit of http://asp.net and started adding a
few modules. All debuggin localy worked fine but once I put it onto a Windos
Server 2003 I keep getting the following error.

Bad Data.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Security.Cryptography.CryptographicException: Bad
Data.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:


[CryptographicException: Bad Data.
]
System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr hKey,
Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone) +0

System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount) +805
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +40
System.Web.Configuration.MachineKey.EncryptOrDecryptData(Boolean
fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length) +139
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
+114
ASPNET.StarterKit.Portal.Global.Application_AuthenticateRequest(Object
sender, EventArgs e) +591

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573



The code where I believe this orignates from is the Cookie encryption which
looks like the following:

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)

If Request.IsAuthenticated = True Then

Dim roles() As String

' Create the roles cookie if it doesn't exist yet for this session.
If Request.Cookies("portalroles") Is Nothing Then

' Get roles from UserRoles table, and add to cookie
Dim _user As New UsersDB()
roles = _user.GetRoles(User.Identity.Name)

' Create a string to persist the roles
Dim roleStr As String = ""
Dim role As String

For Each role In roles

roleStr += role
roleStr += ";"

Next role

' Create a cookie authentication ticket.
' version
' user name
' issue time
' expires every hour
' don't persist cookie
' roles
Dim ticket As New FormsAuthenticationTicket(1, _
Context.User.Identity.Name, _
CDate(DateTime.Now), _
CDate(DateTime.Now.AddHours(1)), _
False, _
roleStr)

' Encrypt the ticket
Dim cookieStr As String =
FormsAuthentication.Encrypt(ticket)

' Send the cookie to the client
Response.Cookies("portalroles").Value = cookieStr
Response.Cookies("portalroles").Path = "/"
Response.Cookies("portalroles").Expires = DateTime.Now.AddMinutes(1)

Else

' Get roles from roles cookie
Dim ticket As FormsAuthenticationTicket =
FormsAuthentication.Decrypt(Context.Request.Cookies("portalroles").Value)

'convert the string representation of the role data into
a string array
Dim userRoles As New ArrayList()

Dim role As String
Dim _user As New UsersDB
For Each role In ticket.UserData.Split(New Char() {";"c})
userRoles.Add(role)
Next role

roles = CType(userRoles.ToArray(GetType(String)),
String())

End If

' Add our own custom principal to the request containing the roles in
the auth ticket
Context.User = New GenericPrincipal(Context.User.Identity, roles)

End If

End Sub


I have tried to take the encryption out but that resulted in a
The viewstate is invalid for this page and might be corrupted error.

The curious thing is that it only happens on IE. I tried it with Firefox and
others and never have a problem so it seems to have to do with the IE Cookie
Corruption problem.

Any advise is appreciated.
 
G

Guest

I am getting the same error. It worked fine before installing .Net SP1.
Works ok in Firefox but not in IE.

Were you able to find a solution?

ERamirez said:
I downloaded the Portal Starter Kit of http://asp.net and started adding a
few modules. All debuggin localy worked fine but once I put it onto a Windos
Server 2003 I keep getting the following error.

Bad Data.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Security.Cryptography.CryptographicException: Bad
Data.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:


[CryptographicException: Bad Data.
]
System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr hKey,
Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone) +0

System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount) +805
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +40
System.Web.Configuration.MachineKey.EncryptOrDecryptData(Boolean
fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length) +139
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
+114
ASPNET.StarterKit.Portal.Global.Application_AuthenticateRequest(Object
sender, EventArgs e) +591

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573



The code where I believe this orignates from is the Cookie encryption which
looks like the following:

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)

If Request.IsAuthenticated = True Then

Dim roles() As String

' Create the roles cookie if it doesn't exist yet for this session.
If Request.Cookies("portalroles") Is Nothing Then

' Get roles from UserRoles table, and add to cookie
Dim _user As New UsersDB()
roles = _user.GetRoles(User.Identity.Name)

' Create a string to persist the roles
Dim roleStr As String = ""
Dim role As String

For Each role In roles

roleStr += role
roleStr += ";"

Next role

' Create a cookie authentication ticket.
' version
' user name
' issue time
' expires every hour
' don't persist cookie
' roles
Dim ticket As New FormsAuthenticationTicket(1, _
Context.User.Identity.Name, _
CDate(DateTime.Now), _
CDate(DateTime.Now.AddHours(1)), _
False, _
roleStr)

' Encrypt the ticket
Dim cookieStr As String =
FormsAuthentication.Encrypt(ticket)

' Send the cookie to the client
Response.Cookies("portalroles").Value = cookieStr
Response.Cookies("portalroles").Path = "/"
Response.Cookies("portalroles").Expires = DateTime.Now.AddMinutes(1)

Else

' Get roles from roles cookie
Dim ticket As FormsAuthenticationTicket =
FormsAuthentication.Decrypt(Context.Request.Cookies("portalroles").Value)

'convert the string representation of the role data into
a string array
Dim userRoles As New ArrayList()

Dim role As String
Dim _user As New UsersDB
For Each role In ticket.UserData.Split(New Char() {";"c})
userRoles.Add(role)
Next role

roles = CType(userRoles.ToArray(GetType(String)),
String())

End If

' Add our own custom principal to the request containing the roles in
the auth ticket
Context.User = New GenericPrincipal(Context.User.Identity, roles)

End If

End Sub


I have tried to take the encryption out but that resulted in a
The viewstate is invalid for this page and might be corrupted error.

The curious thing is that it only happens on IE. I tried it with Firefox and
others and never have a problem so it seems to have to do with the IE Cookie
Corruption problem.

Any advise is appreciated.
 
G

Gunnysack

This one is killing me too. Dear God in Heaven please help!

Andrew said:
*I am getting the same error. It worked fine before installing .Net
SP1.
Works ok in Firefox but not in IE.

Were you able to find a solution?

ERamirez said:
I downloaded the Portal Starter Kit of http://asp.net and started adding a
few modules. All debuggin localy worked fine but once I put it onto a Windos
Server 2003 I keep getting the following error.

Bad Data.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details:
System.Security.Cryptography.CryptographicException: Bad
Data.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:


[CryptographicException: Bad Data.
]
System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr
hKey,
Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone) +0

System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount) +805
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +40
System.Web.Configuration.MachineKey.EncryptOrDecryptData(Boolean
fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length) +139
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
+114
ASPNET.StarterKit.Portal.Global.Application_AuthenticateRequest(Object
sender, EventArgs e) +591

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573



The code where I believe this orignates from is the Cookie encryption which
looks like the following:

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)

If Request.IsAuthenticated = True Then

Dim roles() As String

' Create the roles cookie if it doesn't exist yet for this session.
If Request.Cookies("portalroles") Is Nothing Then

' Get roles from UserRoles table, and add to cookie
Dim _user As New UsersDB()
roles = _user.GetRoles(User.Identity.Name)

' Create a string to persist the roles
Dim roleStr As String = ""
Dim role As String

For Each role In roles

roleStr += role
roleStr += ";"

Next role

' Create a cookie authentication ticket.
' version
' user name
' issue time
' expires every hour
' don't persist cookie
' roles
Dim ticket As New FormsAuthenticationTicket(1, _
Context.User.Identity.Name, _
CDate(DateTime.Now), _
CDate(DateTime.Now.AddHours(1)), _
False, _
roleStr)

' Encrypt the ticket
Dim cookieStr As String =
FormsAuthentication.Encrypt(ticket)

' Send the cookie to the client
Response.Cookies("portalroles").Value = cookieStr
Response.Cookies("portalroles").Path = "/"
Response.Cookies("portalroles").Expires = DateTime.Now.AddMinutes(1)

Else

' Get roles from roles cookie
Dim ticket As FormsAuthenticationTicket =
FormsAuthentication.Decrypt(Context.Request.Cookies("portalroles").Value)

'convert the string representation of the role data into
a string array
Dim userRoles As New ArrayList()

Dim role As String
Dim _user As New UsersDB
For Each role In ticket.UserData.Split(New Char() {";"c})
userRoles.Add(role)
Next role

roles = CType(userRoles.ToArray(GetType(String)),
String())

End If

' Add our own custom principal to the request containing the roles in
the auth ticket
Context.User = New GenericPrincipal(Context.User.Identity, roles)

End If

End Sub


I have tried to take the encryption out but that resulted in a
The viewstate is invalid for this page and might be corrupted error.

The curious thing is that it only happens on IE. I tried it with Firefox and
others and never have a problem so it seems to have to do with the IE Cookie
Corruption problem.

Any advise is appreciated.
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top