473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Bad Data Error

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.CryptographicExceptio n: 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._D ecryptData(IntPtr hKey,
Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone) +0

System.Security.Cryptography.CryptoAPITransform.Tr ansformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount) +805
System.Security.Cryptography.CryptoStream.FlushFin alBlock() +40
System.Web.Configuration.MachineKey.EncryptOrDecry ptData(Boolean
fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length) +139
System.Web.Security.FormsAuthentication.Decrypt(St ring encryptedTicket)
+114
ASPNET.StarterKit.Portal.Global.Application_Authen ticateRequest(Object
sender, EventArgs e) +591

System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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.Cookie s("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.

Nov 18 '05 #1
1 4544

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

Andrew Bornand wrote:
*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" wrote:
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.CryptographicExceptio n: 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._D ecryptData(IntPtr
hKey,
Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone) +0

System.Security.Cryptography.CryptoAPITransform.Tr ansformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount) +805
System.Security.Cryptography.CryptoStream.FlushFin alBlock() +40

System.Web.Configuration.MachineKey.EncryptOrDecry ptData(Boolean
fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length)

+139
System.Web.Security.FormsAuthentication.Decrypt(St ring

encryptedTicket)
+114

ASPNET.StarterKit.Portal.Global.Application_Authen ticateRequest(Object
sender, EventArgs e) +591

System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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.Cookie s("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.
*


--
Gunnysack
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
4
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
18
by: robert | last post by:
Is there a ready made function in numpy/scipy to compute the correlation y=mx+o of an X and Y fast: m, m-err, o, o-err, r-coef,r-coef-err ? Or a formula to to compute the 3 error ranges? ...
4
by: Rick | last post by:
I've moved code from a stage machine to the production machine, exact same code works fine on the stage machine, they are both windows 2003 servers, I'm getting a "Cannot generate SSPI context"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.