ERRORE ASSURDO con fireFox

giovedì 29 maggio 2008 - 16.38

ridaria Profilo | Expert

Amici credo che sia io impazzito:

il seguente codice su IE 6.0 e IE 7.0 non fA UNA gRINZA
Lo ho postato tutto, ma il cuore è dove avvio la scrittura dei dati sul DB.

Imports System.Data
Imports System.Data.SqlClient
Partial Class upload
Inherits System.Web.UI.Page

Public Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Dim thumbnail_image As System.Drawing.Image = Nothing
Dim original_image As System.Drawing.Image = Nothing
Dim final_image As System.Drawing.Bitmap = Nothing
Dim graphic As System.Drawing.Graphics = Nothing

Dim ms As System.IO.MemoryStream = Nothing

Try
Dim jpeg_image_upload As HttpPostedFile = Request.Files("Filedata")
original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream)

Dim width As Integer = original_image.Width
Dim height As Integer = original_image.Height
Dim target_width As Integer = 100
Dim target_height As Integer = 100
Dim new_width, new_height As Integer

Dim target_ratio As Double = target_width / target_height
Dim image_ratio As Double = width / height

If target_ratio > image_ratio Then
new_height = target_height
new_width = Math.Floor(image_ratio * target_height)
Else
new_height = Math.Floor(target_width / image_ratio)
new_width = target_width
End If

final_image = New System.Drawing.Bitmap(target_width, target_height)
graphic = System.Drawing.Graphics.FromImage(final_image)
graphic.FillRectangle(New System.Drawing.SolidBrush(System.Drawing.Color.Black), New System.Drawing.Rectangle(0, 0, target_width, target_height))
Dim paste_x As Integer = (target_width - new_width) / 2
Dim paste_y As Integer = (target_height - new_height) / 2
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic '/* new way */
'//graphic.DrawImage(thumbnail_image, paste_x, paste_y, new_width, new_height)
graphic.DrawImage(original_image, paste_x, paste_y, new_width, new_height)

' // Store the thumbnail in the session (Note: this is bad, it will take a lot of memory, but this is just a demo)
ms = New System.IO.MemoryStream()
final_image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)


'Gestione del FIle di Immagine file di immagine
Dim clsGenerale As New Generale
Dim clsFSO As New classeFSO
Dim nomeImage As String = ""
Dim nomeCartella As String = ""
Dim idUtente As Long = clsGenerale.PrelevaIDutente()
Dim clsDB As New ClasseDB
Dim idRecord As Long = 0

nomeCartella = idUtente

'Verifico se esiste la cartelloa dell'Utente, se non esiste la creo. O meglio. Il metoto la crea se non esiste
clsFSO.CreaCartella(Server.MapPath("/ImmaginiUtenti/" & idUtente))


'Avviao una Transazione con cui prelevo l'id del nuovo file di immagine da slavare, lo associo al nome del file di immagine
'Altrimenti come rendo univoco il nome del file??????

'Salva Utente nel DB
Dim errore As Boolean = False
Dim clsBD As New ClasseDB
Dim clsStringhe As New ClasseStringa
Dim myErrore As String
Dim m_conn As SqlConnection
Dim m_cmd As SqlCommand
Dim m_sql As String = ""
Dim ConnStr As String
Dim tx As SqlTransaction
ConnStr = clsDB.getConnString

m_sql = "INSERT INTO utentiImmagini (idUtente, nomeImage) VALUES (@idUtente, @nomeImage) Select @@IDENTITY"
m_conn = New SqlConnection(ConnStr)
m_cmd = New SqlCommand
m_cmd.Connection = m_conn
m_cmd.CommandType = CommandType.Text
m_cmd.CommandText = m_sql

m_cmd.Parameters.Add("@idUtente", SqlDbType.BigInt).Value = idUtente
m_cmd.Parameters.Add("@nomeImage", SqlDbType.NVarChar).Value = ""

m_conn.Open()
tx = m_conn.BeginTransaction()


Try
'Assegno la transazione al comando
m_cmd.Transaction = tx


'Uso executeScalar per recuperare l'Id del record Appena aggiunto
idRecord = CLng(m_cmd.ExecuteScalar())

clsFSO.CreaCartella(Server.MapPath("/provaimage/Prova"))
'Assemblo il nome dell'Immagine
nomeImage = idUtente & "_" & idRecord & "_" & Request.QueryString("tipoImmagine") & "_.jpg"


'SALVO Il FILE di IMMAGINE
original_image.Save(Server.MapPath("/ImmaginiUtenti/" & nomeCartella & "/" & nomeImage))

Dim cmd As SqlCommand
cmd = New SqlCommand
cmd.Connection = m_conn
cmd.CommandType = CommandType.Text
cmd.CommandText = m_sql

cmd.Transaction = tx
cmd.CommandText = "Update utentiImmagini set nomeImage = " & "'" & nomeImage & "' where id = " & idRecord
cmd.ExecuteNonQuery()

'CHIUDE LA TRANSAZIONE
tx.Commit()
Catch ex As Exception
clsFSO.CreaCartella(Server.MapPath("/provaimage/Errore"))
tx.Rollback()
m_conn.Close()
Dispose()

myErrore = ""
Dispose()
Finally
m_conn.Close()
Dispose()
End Try


' // Store the data in my custom Thumbnail object
Dim thumbnail_id As String = DateTime.Now.ToString("yyyyMMddHHmmssfff")
Dim thumb As Thumbnail = New Thumbnail(thumbnail_id, ms.GetBuffer())

' // Put it all in the Session (initialize the session if necessary)
Dim thumbnails As System.Collections.Generic.List(Of Thumbnail) = Session("file_info")
If thumbnails Is Nothing Then
thumbnails = New System.Collections.Generic.List(Of Thumbnail)()
Session("file_info") = thumbnails
End If
thumbnails.Add(thumb)

Response.StatusCode = 200
Response.Write(thumbnail_id)

Catch ex As Exception
' // If any kind of error occurs return a 500 Internal Server error
Response.StatusCode = 500
Response.Write("An error occured")
Response.End()
Finally
' // Clean up
If Not final_image Is Nothing Then
final_image.Dispose()
End If
If Not graphic Is Nothing Then
graphic.Dispose()
End If
If Not original_image Is Nothing Then
original_image.Dispose()
End If
If Not thumbnail_image Is Nothing Then
thumbnail_image.Dispose()
End If

If Not ms Is Nothing Then
ms.Close()
End If

Response.End()
End Try

End Sub
End Class

Su firefox se ne va in errore dopo executeScalar e precisamente:

idRecord = CLng(m_cmd.ExecuteScalar())

Dal momento che questo file viene eseguito richiamato via javaScript, non riesco neanche a prelevare l'errore
Perche non mi fa neanche una cagata di response.write.



Ma l'assurdo è che su fireFox va in errore e su ie no,

Il test l'ho fatto cosi:
ho sostituito "idRecord = CLng(m_cmd.ExecuteScalar())"
con: "idRecord = 2" e fila liscio.
DA pazzi


HELPPPPPPPPP

Ridaria

Brainkiller Profilo | Guru

>Amici credo che sia io impazzito:
>il seguente codice su IE 6.0 e IE 7.0 non fA UNA gRINZA
>Lo ho postato tutto, ma il cuore è dove avvio la scrittura dei
>dati sul DB.

Cosa c'entra il Browser ? Il codice .NET è eseguito server side quindi sul server, i client ricevono tutti lo stesso codice HTML se i parametri forniti sono gli stessi.

Avvia il debugger apri la pagina su Firefox e vai avanti step by step così capisci dove c'è un errore.

Ciao

David De Giacomi | Microsoft MVP
http://blogs.dotnethell.it/david/

ridaria Profilo | Expert

hai ragione, ecco perché mi chiedevo se fossi Impazzito fino al punto di credere che del codice server side potesse essere influnzato dal Browser.

Cmq ho risolto, è un casino, questo sistema di upload i immagini (carino a dire il vero) SWFupload (http://swfupload.org/) usa filmati flah associati con java lato client e poi lancia un paio di routine server side (file aspx).

Il problema risiedeva nel fatto che qualcosa del flash player di firefox andava a far casino nel kookie e nella sessione pertanto non riusciva più a prelevare l'id Utente dalla sessione/kookie, e quindi quel valore null andava a cozzare con il codice server side con il quale scrivevo dati sul DB, creavo cartelle , creavo file di immagine e li salvavo, e quindi mi dava errore.

Ho risolto con un banale post via queryString dell'Id utente connesso.

Ciao e grazie infinite comunque.

Ridaria
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5