Importar esta librería:
using System.Web.Script.Serialization;
Crear la clase DTO:
public class PersonaDTO
{
public string Nombre { get; set; }
public string Apellido { get; set; }
}
Crear el ActionResult:
[HttpGet]
public ActionResult Buscar(int param)
{
var x = new Persona();
x.Nombre = "Juana";
x.Apellido = "Perez";
return Json(x, JsonRequestBehavior.AllowGet);
}
Agregar el código javascript en la vista:
<script>
$(function () {
$.ajax({
data: { 'param': 123 },
url: "@Url.Action("Buscar", "Prueba")",
type: 'GET',
cache: false,
success: function (response) {
alert(response.Nombre);
},
error: function (a, b) {
alert("error fatal");
alert(a.responseText);
}
});
});
</script>
Logger log4net en C# (para una aplicacion web)
1. Bajar log4net con NuGet
2. Dentro de Properties / AssemblyInfo.cs agregar la siguiente línea:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
3. En web.config, agregar lo siguiente:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="output.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="Amazon" />
<acceptOnMatch value="false" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
</log4net>
</configuration>
4. Para utilizarlo (por ejemplo en un controller)
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ClientesController));
public ActionResult Index()
{
log.Info("prueba de log!");
return View();
}
2. Dentro de Properties / AssemblyInfo.cs agregar la siguiente línea:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
3. En web.config, agregar lo siguiente:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="output.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="Amazon" />
<acceptOnMatch value="false" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
</log4net>
</configuration>
4. Para utilizarlo (por ejemplo en un controller)
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ClientesController));
public ActionResult Index()
{
log.Info("prueba de log!");
return View();
}
Diskpart para recuperar y formatear una tarjeta SD
ir a cmd
diskpart
show disk
select disk N
clean
create partition primary
select partition 1
active
format fs=fat32 quick
diskpart
show disk
select disk N
clean
create partition primary
select partition 1
active
format fs=fat32 quick
Crear aplicacion para Raspberry PI en Visual Studio 2015
http://www.genbetadev.com/visualstudio/creando-aplicaciones-iot-con-visual-studio-2015
Instalar NOOBS en Raspberry PI 3
Si la tarjeta es mayor o igual a 64gb, debe ser formateada en FAT32.
Usar esto: http://www.ridgecrop.demon.co.uk/index.htm?guiformat.htm
Luego bajar el NOOBS y copiarlo a la tarjeta
Crystal Reports - Troubleshooting
PROBLEMA 1: Microsoft
ReportViewer runtime
Could not load
file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.
The system cannot find the file specified.
SOLUCION:
INSTALAR: ReportViewer.msi (https://www.microsoft.com/en-us/download/confirmation.aspx?id=35747)
PROBLEMA 2: falta
Microsoft System CLR Types
PROBLEMA 3: Versión del
framework en el app.pool.
Si se reinstala el framework 4.5, todos los app pool quedan
en la versión anterior
SOLUCION: Cambiar el framework de los app. pool a 4.0
PROBLEMA 4: Versiones incorrectas
SOLUCION:
Se debe instalar el runtime (redistributables) de visual
studio, luego el framework 4.5, luego la actualización a 4.5.1 y por último el
cristal reports.
Redistributables
|
vcredist_x64.exe
|
.NET Framework 4.5
|
\\Xvir79\pai$\NET
Framework\dotNetFx45_Full_setup
|
.NET Framework 4.5.1
|
\\Xvir79\pai$\NET
Framework\NDP451-KB2858728-x86-x64-AllOS-ENU\setup.exe
|
Crystal Reports 13.0.2000
|
\\Xvir79\pai$\Crystal Report
2013 - SAP\_Anteriores\CRRuntime_64bit_13_0_10.msi
|
PROBLEMA 5: Error al cargar log4net
Could not load
file or assembly 'log4net, Version=1.2.10.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot
find the file specified.
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.IO.FileNotFoundException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 40:
<asp:Label ID="lblError" runat="server"
Width="282px"></asp:Label><br />
Line 41: <br />
Line 42:
<cr:crystalreportviewer id="CrystalReportViewer1"
runat="server"
autodatabind="true"></cr:crystalreportviewer>
Line
43: <br />
Line 44:
</div>
|
SOLUCION:
Ver si en la carpeta assembly está la dll log4net.
Si no está, bajarla e instalarla.
Si está (como en este caso), fijarse si coincide el número
de versión y el token.
Si coincide, fijarse en el PROCESADOR (en este caso dice
AMD64, por lo cual solamente podrá ser utilizada por aplicaciones y sitios web
que corran en 64 bits exclusivamente).
Revisar el app pool:
En este caso, el problema es que el setting Enable 32-Bit
Applications está en TRUE, por lo cual, cuando la aplicación se ejecuta,
intenta utilizar la versión de 32 bits de la librería log4net, la cual no está
instalada.
La solución es cambiar el setting “Enable 32-Bit
Application” a FALSE:
PROBLEMA 6: Error al
cargar dll’s de cristal
Configuration Error
Description: An error occurred during the processing of a configuration file required
to service this request. Please review the specific error details below and
modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Parser Error Message: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 27: <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 28: <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 29: <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 30: <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
Line 28: <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 29: <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 30: <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
Line 31: <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
SOLUCION:
Revisar el assembly.
En este caso, la librería
CrystalDecisions.ReportAppServer.ClientDoc existe, pero su procesador para la
versión 13.0.2000, es AMD64, por lo cual no admite aplicaciones 32 bits.
La solución es cambiar en el app.pool el setting “Enable
32-Bit Application” a FALSE, tal como en el caso anterior.
PROBLEMA 7: Restricciones de ISAPI
Si se reinstala el .net
framework, pueden quedar deshabilitadas las extensiones ISAPI.
SOLUCION:
Cambiar el valor Restriction a “Allowed”, para ASP.NET v4.0
(los dos settings)
The page
you are requesting cannot be served because of the ISAPI and CGI Restriction
list settings on the Web server
PROBLEMA 8: Pipeline
mode
This operation requires IIS integrated pipeline mode.
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.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.
Exception Details: System.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.
SOLUCION:
Crystal Reports - Troubleshooting
PROBLEMA 1: Microsoft
ReportViewer runtime
Could not load
file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.
The system cannot find the file specified.
SOLUCION:
INSTALAR: ReportViewer.msi (https://www.microsoft.com/en-us/download/confirmation.aspx?id=35747)
PROBLEMA 2: falta
Microsoft System CLR Types
PROBLEMA 3: Versión del
framework en el app.pool.
Si se reinstala el framework 4.5, todos los app pool quedan
en la versión anterior
SOLUCION: Cambiar el framework de los app. pool a 4.0
PROBLEMA 4: Versiones incorrectas
SOLUCION:
Se debe instalar el runtime (redistributables) de visual
studio, luego el framework 4.5, luego la actualización a 4.5.1 y por último el
cristal reports.
Redistributables
|
vcredist_x64.exe
|
.NET Framework 4.5
|
\\Xvir79\pai$\NET
Framework\dotNetFx45_Full_setup
|
.NET Framework 4.5.1
|
\\Xvir79\pai$\NET
Framework\NDP451-KB2858728-x86-x64-AllOS-ENU\setup.exe
|
Crystal Reports 13.0.2000
|
\\Xvir79\pai$\Crystal Report
2013 - SAP\_Anteriores\CRRuntime_64bit_13_0_10.msi
|
PROBLEMA 5: Error al cargar log4net
Could not load
file or assembly 'log4net, Version=1.2.10.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot
find the file specified.
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.IO.FileNotFoundException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 40:
<asp:Label ID="lblError" runat="server"
Width="282px"></asp:Label><br />
Line 41: <br />
Line 42:
<cr:crystalreportviewer id="CrystalReportViewer1"
runat="server"
autodatabind="true"></cr:crystalreportviewer>
Line
43: <br />
Line 44:
</div>
|
SOLUCION:
Ver si en la carpeta assembly está la dll log4net.
Si no está, bajarla e instalarla.
Si está (como en este caso), fijarse si coincide el número
de versión y el token.
Si coincide, fijarse en el PROCESADOR (en este caso dice
AMD64, por lo cual solamente podrá ser utilizada por aplicaciones y sitios web
que corran en 64 bits exclusivamente).
Revisar el app pool:
En este caso, el problema es que el setting Enable 32-Bit
Applications está en TRUE, por lo cual, cuando la aplicación se ejecuta,
intenta utilizar la versión de 32 bits de la librería log4net, la cual no está
instalada.
La solución es cambiar el setting “Enable 32-Bit
Application” a FALSE:
PROBLEMA 6: Error al
cargar dll’s de cristal
Configuration Error
Description: An error occurred during the processing of a configuration file required
to service this request. Please review the specific error details below and
modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Parser Error Message: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 27: <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 28: <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 29: <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 30: <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
Line 28: <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 29: <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
Line 30: <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
Line 31: <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
SOLUCION:
Revisar el assembly.
En este caso, la librería
CrystalDecisions.ReportAppServer.ClientDoc existe, pero su procesador para la
versión 13.0.2000, es AMD64, por lo cual no admite aplicaciones 32 bits.
La solución es cambiar en el app.pool el setting “Enable
32-Bit Application” a FALSE, tal como en el caso anterior.
PROBLEMA 7: Restricciones de ISAPI
Si se reinstala el .net
framework, pueden quedar deshabilitadas las extensiones ISAPI.
SOLUCION:
Cambiar el valor Restriction a “Allowed”, para ASP.NET v4.0
(los dos settings)
The page
you are requesting cannot be served because of the ISAPI and CGI Restriction
list settings on the Web server
PROBLEMA 8: Pipeline
mode
This operation requires IIS integrated pipeline mode.
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.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.
Exception Details: System.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.
SOLUCION:
Ejemplo de JqueryUI Autocomplete cuando el source no contiene label y value
Fuente: http://www.jensbits.com/2011/08/24/using-jquery-autocomplete-when-remote-source-json-does-not-contain-label-or-value-fields/
Using jQuery Autocomplete When Remote Source JSON Does Not Contain ‘Label’ or ‘Value’ Fields
If the jQuery autocomplete plugin uses a remote datasource, the autocomplete expects it to return json data with a ‘label’ and/or a ‘value’ field. If you return one, either ‘label’ or ‘value’, the autocomplete uses it for both the suggestion menu and the value of the input box. If you return both, it uses the ‘label’ for the suggestion menu and the ‘value’ for the value of the input box.
What happens when the remote source returns neither a ‘label’ or ‘value’ and you cannot change the returned json of the remote source? Or, better yet, it does return them but you want different values used in the autocomplete?
For example, the remote source json string below has neither a ‘label’ or a ‘value’ field. Using this would result in the autocomplete not functioning at all.
[{"id":"3","state":"Alaska","abbrev":"AK"},{"id":"4","state":"Alabama","abbrev":"AL"},{"id":"9","state":"California","abbrev":"CA"}] |
You can work around this by modifying the ‘source’ option of the autocomplete to assign one or both of the ‘label’ and ‘value’ fields values found in the json result.
To modify the ‘source’ option of the autocomplete, we add an ajax call to the source and, in the ‘success’ callback, we assign the values of all the variables we want the autocomplete to use.
$("#state").autocomplete({ |
source: function( request, response ) { |
$.ajax({ |
url: "states_remote.php", |
dataType: "json", |
data: {term: request.term}, |
success: function(data) { |
response($.map(data, function(item) { |
return { |
label: item.state, |
id: item.id, |
abbrev: item.abbrev |
}; |
})); |
} |
}); |
}, |
minLength: 2, |
select: function(event, ui) { |
$('#state_id').val(ui.item.id); |
$('#abbrev').val(ui.item.abbrev); |
} |
}); |
To break this down, the ajax function has the following options:
- url: url of page that returns the json; subject to same origin policy (you should use jsonp for cross-domain url’s)
- dataType: sets the data coming back to the ajax function as json
- data: sets the query parameter of ‘term’ to the value of ‘request.term’ which is what the user types into the input box
- success: callback function that maps the returned json and sets the variables that the autcomplete will use
In this example, the ‘select’ option of the autocomplete sets the label field used by the autocomplete in the suggest menu and as the value of the input box. It also sets the values of some additional fields in the form. They are returned to the page in the demo to verify that they are set. ‘id’ is a hidden field in the form and ‘abbrev’ populates a read-only input box in the form.
And, if the json result does set the ‘label’ and/or ‘value’ fields but you don’t want those values in the autocomplete, you can adjust the ‘return’ of the ‘success’ function in th ‘ajax’ call:
return { |
label: item.value, |
yourVar1: item.id, |
yourVar2: item.label |
}; |
// or however you want it as long as a 'label' and/or 'value' field is set |
Remember, the autocomplete needs a ‘label’ or ‘value’. Don’t forget to set one, the other, or both.
Suscribirse a:
Entradas (Atom)




