vbdotnet.it

Tricks & tips, workaround, forum and ideas with .Net

About the author

Enrico Rossini è il gestore di questo blog.
E-mail me Send mail

Recent posts

Recent comments

Contributi

Best 6 ~ 6 users ~ 6 comments

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce. I marchi citati sono delle rispettive aziende.

© Copyright 2010

Advertising


Convalida di viewstate MAC non riuscita

Oggi mi è capitato un errore interessante che è il seguente:

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]

Il problema è che il mio PC portatile ha Vista e non ha alcun tipo di cluster e non è sicuramente in una webfarm.

Ho rilevato che il bug si verifica con i controlli Data (gridview, datalist, formview) di ASP.NET che usano il DataKeyName o in pagine lente. Un’altra possibilità è che il form sia multipart e si sia definito nel tag form un’action su una pagina diversa.

La soluzione è di aggiungere nella sezione pages alcuni parametri:

   1:  <configuration>
   2:     <system.web>
   3:        <pages enableEventValidation="false" enableViewStateMac="false" viewStateEncryptionMode ="Never" >
   4:     </system.web>
   5:  </configuration>

Ciao, buon lavoro

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: asp.net
Posted by enrico on Wednesday, January 28, 2009 2:57 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Esportare un report di Crystal Report direttamente in PDF con ASP.NET

Già creare un report alle volte non è una cosa velocissima ma quando all’utente gli viene proposta la pagina di selezione di tipologia di report da stampare, va in panico. È meglio quindi far in modo che il report creato con Crystal Report venga subito visualizzato in un file PDF.

La risoluzione è abbastanza semplice. Innanzitutto inserire gli opportuni import che sono i seguenti:

   1:  Imports CrystalDecisions.CrystalReports.Engine
   2:  Imports CrystalDecisions.Shared
   3:  Imports CrystalDecisions.Web.Design

Poi nella funzione di generazione dei report e del suo binding, inserire questo codice (oReport è di tipo ReportDocument):

   1:  Dim objMem As New MemoryStream
   2:  objMem = CType(oReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat), System.IO.MemoryStream)
   3:  oReport.Close()
   4:   
   5:  Response.Clear()
   6:  Response.AddHeader("content-disposition", "attachment;filename=Export.pdf")
   7:  Response.Buffer = True
   8:  Response.ContentType = "application/pdf"
   9:  Response.BinaryWrite(objMem.ToArray())
  10:  Response.End()

Ciao.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, January 22, 2009 4:36 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Selezionare un’opzione di un menu in ASP.NET

Mi è capitato di aver un controllo menu di ASP.NET creato dinamicamente in un form ASPX. Ogni elemento del menu ha un valore. Il mio problema era di selezionare il menu con il valore che mi interessava.

Dopo un po’ di ricerche molti hanno avuto il mio stesso problema e quindi ho deciso di postare la soluzione per altro semplice. Si presume che il controllo menu nel form si chiami Menu1.

   1:  Dim mi As MenuItem = Me.Menu1.FindItem(Request.QueryString("VoceMenu"))
   2:  mi.Selected = True

Buon lavoro a tutti!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, January 22, 2009 3:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Generazione di un nome di file temporaneo

Alle volte può essere necessario generate un file con un nome temporaneo. Per poter inventare un nome, esiste una funzione del namespace System.IO che fa al caso nostro.

Dim sTempFileName As String = System.IO.Path.GetRandomFileName

Ciao, a presto!

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Friday, January 09, 2009 11:39 PM
Permalink | Comments (0) | Post RSSRSS comment feed