Archive

Posts Tagged ‘asp.net’

AjaxControlToolkit rilasciata la versione 15.1 l’atteso ajax lato server per Asp.net

ASP.net Ajax  Rilasciata l’attesa nuova versione dell’ AJAX Control Toolkit l’utile Ajax lato server per Asp.Net. L’ultima rilascio del dicembre 2013 lasciava un po’ a desiderare tant’è che  si avvertiva la necessità di un aggiornamento. Con la nuova versione la v15.1 c’è stato un significativo lavoro di revisione e miglioramento che evidenzia al primo impatto maggiore velocità e stabilità dei componenti.   Le novità della nuova versione che ha come nuovo mantainer DevExpress: What’s new.

Con la nuova versione termina il supporto alle versioni di Asp.Net precedenti la 4.0.

Unica nota dolente è disponibile, al momento,  solo la versione installabile che necessita della presenza di Visual Studio. Va considerato che ora  è disponibile una versione free di Visual Studio: la versione community.

Comunque una volta installata la versione del Control Toolkit, e creata la prima web application per aggiornare altre web application che fanno uso dell’Ajax  Control ToolKit sarà sufficiente :

  • prelevare i binari dalla cartella /bin e copiarli nella web application da aggiornare sostituendo quindi i files della precedente versione
  • apportare le modifiche base per l’utilizzo della nuova versione in particolare la sostituzione del controllo  <ajaxToolkit:ToolkitScriptManager …  con <asp:ScriptManager  ….
    Esemplificando

    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

    ora va sostituito con

    <asp:ScriptManager ID="ScriptManager2" runat="server" />


  • Eliminare se presenti dal web.config i riferimenti alla precedente versione del Control ToolKit
    come indicato in   Upgrade your project to AjaxControlToolkit v15.1 .
    Di fatto in web.config è sufficiente dichiarare il namespace AjaxControlToolkit

    <system.web>
    ......
       <pages>
           <controls>     
    ......
             <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
           </controls>
       </pages>
    </system.web>

 

Risorse:

 

IIS 8.0 There is a duplicate ‘system.web.extensions/scripting/scriptResourceHandler’ section defined

Trasferendo una web application ASP.NET da Windows 2008 server con IIS 7.5  a Windows Server 2012 con  IIS 8.0 può capitare di riscontrare il seguente messaggio di errore

There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' 
section defined

Due soluzioni possibili:

1) L’applicazione è assegnata ad un’ Application Pools non appropriato:
I progetti sviluppati con i frameworks dalla versione  2.0 alla verione 3.5 vanno assegnati ad un Application Pools con .NET FRAMEWORK VERSION v2.0.xxxx

I progetti sviluppati con in 4.0 e seguenti vanno assegnati ad un Application pools con .NET FRAMEWORK VERSION v4.0.xxxxx

Application Pools in Windows 2012 server con IIS 8.0

Application Pools

Applications Pools

2) Disabilitare commentando con <!–   –> le righe della sezione <sectionGroup name=”system.web.extensions”…> per le quali viene presentato il messaggio. Valutare adirittura di estendere il commento a tutta la sezione system.web.extension presente all’inizio ovviamente del file di configurazione web.config.

Esempio di commento

<!–section name=”scriptResourceHandler” type=”System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication” /–>

Una volta commentate le righe ho sperimentato il funzionamento di applicazioni ASP.NET versione 3.5 anche una volta associate ad Application Pools 4.0

...
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
   <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
         <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
         <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
         <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
         <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
      </sectionGroup>
    </sectionGroup>
</sectionGroup>
...

Risorse:

Asp.net web.config differenze tra versione 3.5 e 4.5

settembre 12, 2013 Lascia un commento

Di seguito le modifiche ad un file web.config di asp.net versione 3.5 affinchè risulti compatibile con la versione 4.5 del framework di asp.net. In generale la versione 4.5 di asp.net è più snella molte dichiarazioni non sono più necessarie.

Nel primo file compatibile con il framework asp.net 3.5 sono evidenziate:

  • in rosso sezioni/righe  tipiche del framework 3.5 che vengono eliminate nel 4.5
  • in blue quelle modificate
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
     <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
 <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>
 <!-- application specific settings -->
 <appSettings>
    <add key="Server" value="192.168.1.157"/>
    <add key="DownloadareaMainPhysicalPath" value="G:\www\downloadarea" />
    ....      
 </appSettings>
 <system.webServer>
   <security>
     <requestFiltering allowDoubleEscaping="true" />
   </security>
     <modules>
        <remove name="ScriptModule" />
        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     </modules>
     <handlers>
         <remove name="WebServiceHandlerFactory-Integrated" />
         <remove name="ScriptHandlerFactory" />
         <remove name="ScriptHandlerFactoryAppServices" />
         <remove name="ScriptResource" />
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
 </handlers>
 </system.webServer>
 <system.web>
   <!-- globalization culture -->
   <globalization culture="it-IT" uiCulture="it-IT" requestEncoding="iso-8859-1" responseEncoding="iso-8859-1" />

 <sessionState timeout="15" />
 <!--
     Set compilation debug="true" to insert debugging
     symbols into the compiled page. Because this
     affects performance, set this value to true only
     during development.
 -->
 <compilation debug="true" defaultLanguage="c#">
    <assemblies>
       <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
       <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
       <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
       <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    </assemblies>
  </compilation>
  <httpHandlers>
     <remove verb="*" path="*.asmx" />
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
  </httpHandlers>
  <httpModules>
         <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </httpModules>
 <!-- Portal supports either Forms authentication (Internet)
 or Windows authentication (for intranets). Forms Authentication is
 the default. To change to Windows authentication, comment the
 <authentication mode="Forms"> section below, and uncomment the
 <authentication mode="Windows"> section. -->
 <authentication mode="Forms">
    <!-- default timeout value 30 min (the timeout value is in minutes)-->
    <forms name=".ASPXFORMSAUTH" protection="All" timeout="60" />
    <!--forms name=".ASPXAUTH" protection="All" timeout="60" /-->
 </authentication>
 <!--<authentication mode="Windows" />
    <authorization>
    <deny users="?" />
 </authorization>-->

 <httpRuntime executionTimeout="500" maxRequestLength="10000" useFullyQualifiedRedirectUrl="true" />
 <urlMappings>
    <add url="~/AccessDenied.aspx" mappedUrl="~/portal.aspx?pg=access denied" />
    .... 
 </urlMappings>
 <customErrors mode="RemoteOnly">
     <error statusCode="405" redirect="~/portal.aspx?pg=HTTP 405" />
     <error statusCode="505" redirect="~/portal.aspx?pg=HTTP 505" />
     ...
 </customErrors>
 <pages validateRequest="false" enableViewStateMac="false" viewStateEncryptionMode="Auto">
    <namespaces>
       <add namespace="System.Globalization" />
       <add namespace="ASPNetPortal" />
       <add namespace="ASPNetPortal.Web.UI" />
    </namespaces>
    <controls>
       <add tagPrefix="ap" namespace="ASPNetPortal.Web.UI.WebControls" />
             <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
       <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit" />
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </controls>
 </pages>
 <!-- Adapter configuration for mobile controls used in the portal -->
 <mobileControls>
   <device name="PortalHtmlDeviceAdapters" inheritsFrom="HtmlDeviceAdapters">
      <control name="ASPNetPortal.MobileControls.TabbedPanel, Portal" adapter="ASPNetPortal.MobileControls.HtmlTabbedPanelAdapter,Portal" />
      <control name="ASPNetPortal.MobileControls.LinkCommand, Portal" adapter="ASPNetPortal.MobileControls.HtmlLinkCommandAdapter,Portal" />
   </device>
   <device name="PortalChtmlDeviceAdapters" inheritsFrom="ChtmlDeviceAdapters">
     <control name="ASPNetPortal.MobileControls.TabbedPanel, Portal" adapter="ASPNetPortal.MobileControls.ChtmlTabbedPanelAdapter,Portal" />
   </device>
   <device name="PortalWmlDeviceAdapters" inheritsFrom="WmlDeviceAdapters">
      <control name="ASPNetPortal.MobileControls.TabbedPanel, Portal" adapter="ASPNetPortal.MobileControls.WmlTabbedPanelAdapter,Portal" />
   </device>
 </mobileControls>
 <!-- Mobile device filters used for customizing portal -->
 <deviceFilters>
    <filter name="isJScript" compare="javascript" argument="true" />
    <filter name="isPocketIE" compare="browser" argument="Pocket IE" />
    <filter name="isHTML32" compare="preferredRenderingType" argument="html32" />
 </deviceFilters>
 </system.web>

 <location path="Admin">
   <system.web>
      <pages theme="ThAdmin" masterPageFile="~/TemplateAdmin.master" maintainScrollPositionOnPostBack="true"></pages>
   </system.web>
 </location>
 <location path="DesktopModules/EditMenu.aspx">
    <system.web>
       <pages theme="ThAdmin" masterPageFile="~/TemplateAdmin.master" maintainScrollPositionOnPostBack="true"></pages>
    </system.web>
 </location>
 ...
  
 <system.webServer>
 <directoryBrowse enabled="false" />
 <validation validateIntegratedModeConfiguration="false" />
 </system.webServer>
 <system.codedom>
   <compilers>
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
          <providerOption name="CompilerVersion" value="v3.5" />
          <providerOption name="WarnAsError" value="false" />
     </compiler>
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
          <providerOption name="CompilerVersion" value="v3.5" />
          <providerOption name="OptionInfer" value="true" />
          <providerOption name="WarnAsError" value="false" />
      </compiler>
   </compilers>
 </system.codedom>
 <runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727">
     <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
     </dependentAssembly>
     <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
     </dependentAssembly>
   </assemblyBinding>
 </runtime>
</configuration>


La versione 4.5 dello stesso web.config  decisamente più snella

<?xml version="1.0"?>
<configuration>

 <!-- application specific settings -->
 <appSettings>
    <add key="Server" value="192.168.1.157"/>
    <add key="DownloadareaMainPhysicalPath" value="G:\www\downloadarea" />
    ....      
 </appSettings>
 <system.webServer>
   <security>
     <requestFiltering allowDoubleEscaping="true" />
   </security>
 </system.webServer>
 <system.web>
   <!-- globalization culture -->
   <globalization culture="it-IT" uiCulture="it-IT" requestEncoding="iso-8859-1" responseEncoding="iso-8859-1" />

 <sessionState timeout="15" />
 <!--
     Set compilation debug="true" to insert debugging
     symbols into the compiled page. Because this
     affects performance, set this value to true only
     during development.
 -->
  <compilation debug="true" defaultLanguage="c#" targetFramework="4.5"/>
 <!-- Portal supports either Forms authentication (Internet)
 or Windows authentication (for intranets). Forms Authentication is
 the default. To change to Windows authentication, comment the
 <authentication mode="Forms"> section below, and uncomment the
 <authentication mode="Windows"> section. -->
 <authentication mode="Forms">
    <!-- default timeout value 30 min (the timeout value is in minutes)-->
    <forms name=".ASPXFORMSAUTH" protection="All" timeout="60" />
    <!--forms name=".ASPXAUTH" protection="All" timeout="60" /-->
 </authentication>
 <!--<authentication mode="Windows" />
    <authorization>
    <deny users="?" />
 </authorization>-->

 <httpRuntime executionTimeout="500" maxRequestLength="10000" useFullyQualifiedRedirectUrl="true" />
 <urlMappings>
    <add url="~/AccessDenied.aspx" mappedUrl="~/portal.aspx?pg=access denied" />
    .... 
 </urlMappings>
 <customErrors mode="RemoteOnly">
     <error statusCode="405" redirect="~/portal.aspx?pg=HTTP 405" />
     ...
 </customErrors>
 <pages validateRequest="false" enableViewStateMac="false" viewStateEncryptionMode="Auto" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
     <namespaces>
       <add namespace="System.Globalization" />
       <add namespace="ASPNetPortal" />
       <add namespace="ASPNetPortal.Web.UI" />
    </namespaces>
    <controls>
       <add tagPrefix="ap" namespace="ASPNetPortal.Web.UI.WebControls" />
       <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit" />
    </controls>
 </pages>
 <!-- Adapter configuration for mobile controls used in the portal -->
 <mobileControls>
   <device name="PortalHtmlDeviceAdapters" inheritsFrom="HtmlDeviceAdapters">
      <control name="ASPNetPortal.MobileControls.TabbedPanel, Portal" adapter="ASPNetPortal.MobileControls.HtmlTabbedPanelAdapter,Portal" />
      <control name="ASPNetPortal.MobileControls.LinkCommand, Portal" adapter="ASPNetPortal.MobileControls.HtmlLinkCommandAdapter,Portal" />
   </device>
   <device name="PortalChtmlDeviceAdapters" inheritsFrom="ChtmlDeviceAdapters">
     <control name="ASPNetPortal.MobileControls.TabbedPanel, Portal" adapter="ASPNetPortal.MobileControls.ChtmlTabbedPanelAdapter,Portal" />
   </device>
   <device name="PortalWmlDeviceAdapters" inheritsFrom="WmlDeviceAdapters">
      <control name="ASPNetPortal.MobileControls.TabbedPanel, Portal" adapter="ASPNetPortal.MobileControls.WmlTabbedPanelAdapter,Portal" />
   </device>
 </mobileControls>
 <!-- Mobile device filters used for customizing portal -->
 <deviceFilters>
    <filter name="isJScript" compare="javascript" argument="true" />
    <filter name="isPocketIE" compare="browser" argument="Pocket IE" />
    <filter name="isHTML32" compare="preferredRenderingType" argument="html32" />
 </deviceFilters>
 </system.web>

 <location path="Admin">
   <system.web>
      <pages theme="ThAdmin" masterPageFile="~/TemplateAdmin.master" maintainScrollPositionOnPostBack="true"></pages>
   </system.web>
 </location>
 <location path="DesktopModules/EditMenu.aspx">
    <system.web>
       <pages theme="ThAdmin" masterPageFile="~/TemplateAdmin.master" maintainScrollPositionOnPostBack="true"></pages>
    </system.web>
 </location>
 ...
  
 <system.webServer>
 <directoryBrowse enabled="false" />
 <validation validateIntegratedModeConfiguration="false" />
 </system.webServer>
</configuration>


L

Compatiblità di explorer con asp.net – hotfix problemi di visualizzazione

Non è una novità che Microsoft rilasci nuovi prodotti che finiscono per avere problemi di compatibilità con la tecnologia che Microsoft stessa promuove.  Uno di questi casi è il borwser Explorer in particolare la versione 10 che accedendo a siti sviluppati con asp.net, framework per web application promosso da Microsft,  presenta problemi di visualizzazione e interazione.  Può sembrare paradossale ma il problema affligge anche le web application di Microsoft come Sharepoint (SharePoint 2007, SharePoint 2010 and IE10 compatibility – Oliver Wirkus – SharePointCommunity ). Va evidenziato poi  che mentre Explorer presenta problmei di compatibilità  Chrome, Firefox e Safari interagiscono correttamente.

Quindi, come tradizione in queste situazioni,  Microsoft è costretta a rilasciare hotfix per risolvere il problema.  Nel caso specifico è possibile utilizare lo hotfix A hotfix is available for the ASP.NET browser definition files in the .NET Framework 2.0 SP2 and in the .NET Framework 3.5 SP1 che consente di aggiornare il i files con le definizioni dei browsers presenti in .NET Framework 2.0 SP2 e ..NET Framework 3.5 SP1. E’ necessario scaricare o farsi inviare via email come indicato in http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2600100&kbln=en-us  lo hotfix specifico per il proprio  sistemi operativo.  Nel caso di Windows Server 2008 R2 64 bit, il file scaricato, decompresso,  è di tipo .msu. Windows6.1-KB2600100-x64.msu si installa automaticamente ma richiede il riavvio del sistema.

Hotfix Kb2600100

Hotfix Kb2600100

 

Hotfix Kb2600100 update

Hotfix Kb2600100 update

 

Hotfix Kb2600100 restart

Hotfix Kb2600100 restart

 

 

System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client

ASP.NET con il framework 4.0 aumenta i controlli legati alla di sicurezza. Quindi è abbastanza facile aggiornando un sito dalla versione 2.0/3.5 incorrere nell’errore :

System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client

Soprattutto quando si editano form dedicati l’aggiornamento dei contenuti. La soluzione più immediata per superare l’errore è data dall’utilizzo della modalità di validazione di ASP.NET 2.0.

In questo caso nel file web.config

<system.web>
 <httpRuntime requestValidationMode="2.0"/>
 ....
 </ system.web>

Se si è in ASP.NET 4.5 e si richiede il rendering secondo quest’ultima versione la riga potrebbe essere del tipo

<system.web>
    <httpRuntime requestValidationMode="2.0" targetFramework="4.5" />
....
</ system.web>

E’ possibile anche disabilitare globalmente la validazione. La scelta non risulta consigliabile considerato che in ASP.NET la “request validation” conferisce comunque un certo livello di sicurezza contro gli attacchi cross-site scripting ( XSS ).

La disabilitazione globale si effettua disabilitando sempre in <system.web> la Request Validation  per le pagine con

<system.web>
 <pages validateRequest="false" />
  ...
</system.web>

 

Risorse

ASP.NET The variable ‘ex’ is declared but never used

settembre 25, 2012 Lascia un commento

Per evitare questo warning è sufficiente non indicare la variabili

...
...
     try
     {
          myConnection.Open();
          string _tmpquery = "SELECT * FROM tabs WHERE portalid = 0 AND LOWER(tabname) = 'home' ";
          NpgsqlCommand _Command = new NpgsqlCommand(_tmpquery, myConnection);
          dr = _Command.ExecuteReader();
          myConnection.Close();

     }
     catch (Exception ex)
     {
         Response.Redirect(Request.ApplicationPath + "/offline.aspx");               
     }

variabile ex non utilizzata

...
...
     try
     {
        ...
        ... 
     }
     catch (Exception)
     {
         Response.Redirect(Request.ApplicationPath + "/offline.aspx");               
     }

oppure si può utilizzare un modo neutro di utilizzo del eccezione

     }
     catch (Exception ex )
     {
         Response.Redirect(Request.ApplicationPath + "/offline.aspx");               
         message = "Exception message:" + ex ; 
     }

 

Volendo è possibile anche utilizzare pragma warning che consente di abilitare o disabilitare certi warning
#pragma warning (C# Reference)

#pragma warning disable 0168 // variable declared but not used.
#pragma warning disable 0219 // variable assigned but not used.
#pragma warning disable 0414 // private field assigned but not used.

...
...
     try
     {
        ...
        ... 
     }
     #pragma warning disable 0168
     catch (Exception)
     #pragma warning disable 0168
     { 
         Response.Redirect(Request.ApplicationPath + "/offline.aspx");

     }

 

Asp.Net utilizzare Request.Form Collection per recuperare i valori di una Form

Di seguito un esempio per elencare e recuperare i valori contenuti in una Form utilizzando Request.Form Collection in Asp.Net utilizzando la NameValueCollection Class :

Per poter utilizzare la NameValueCollection Class fare riferimento ai namespace:
using System.Collections;
using System.Collections.Specialized;

      
string form_vs, form_v1, form_v2;
           
void Page_Load(Object sender, EventArgs e) {
        ...  	
        x = 0; 
        foreach (string _Fctrl in Request.Form)
        {
            x += 1;
            form_vs += x.ToString() + " " + _Fctrl + ": "; 
            if (x > 5)
            {
               form_vs += "<b>" + Request.Form[_Fctrl] + "<b>" ;
            }
            form_vs += "<br />";             
        }
        ...

Ricercare un valore specifico presente in una Form

foreach (string _Fctrl in Request.Form)
{
   if ( _Fctrl.Contains("email") {
   form_vs += _Fctrl + ": " + "<b>" + Request.Form[_ctl] + "<b><br />" ;
   }
}

Utilizzando NameValueCollection

	    
        //  Read Request Form
        NameValueCollection nvcF = Request.Form;

        int x = 0;
        foreach (string _nvcf in nvcF)
        {
            x += 1;
            form_vs += x.ToString() + " " + _nvcf + ": "; 
            if (x > 5)
            {
                form_vs += "<b>" + nvcF[_nvcf] + "</b>" ;
            }
            form_vs += "<br />";
             
        }

Altro esempio


        if (!string.IsNullOrEmpty(nvcF["ctl00$MainContent$ctl00$email"]))
        {
            form_v2 += nvcF["ctl00$MainContent$ctl00$email"];
        }                           

 

Risultato

Request.Form Collection

Request.Form Collection

 

Risorse: