Skip to main content

Posts

Showing posts from 2018

#XML #C# Read a XML (from a string) and get some fields

string myXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?><myDataz xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><listS> <sog><field1>123</field1><field2>a</field2><field3>b</field3> </sog><sog><field1>456</field1><field2>c</field2><field3>d</field3> </sog></listS></myDataz>" ; XmlDocument xmlDoc = new XmlDocument (); xmlDoc . LoadXml ( xml ); string xpath = "myDataz/listS/sog" ; var nodes = xmlDoc . SelectNodes ( xpath ); foreach ( XmlNode childrenNode in nodes ) {      HttpContext . Current . Response . Write ( childrenNode . SelectSingleNode ( "//field1" ). Value ); } Try :         childrenNode . SelectSingleNode ( "field1" ). Value .InnerText or .InnerXML ----------------------------...

#HTTPRequestHeader- How to get an specific header value from the HttpResponseMessage

How to get an specific header value from the HttpResponseMessage You should be able to use the TryGetValues method. HttpHeaders headers = response . Headers ; IEnumerable <string> values ; if ( headers . TryGetValues ( "X-BB-SESSION" , out values )) {         string session = values . First (); } Note: First() is an extension method; include System.Linq to get access to it.

#C# Data Caching

There are 3 types of caching in ASP.NET: Output Caching Fragmentation Caching Data Caching We implemented " Data Caching " in Cost and scheduling tool. Caching takes place where frequently-used data is stored so that the application can quickly access the data rather than accessing the data from the source. Caching can improve the performance and scalability of the application dramatically and can help us to remove the unnecessary requests to the external data sources for the data that changes infrequently. This is the simplest way of caching. In this technique, cache is stored in the memory of the local Web Server. An in-memory cache is stored into the Server memory which is hosting the ASP.NET application. In the case of Web farm (where the application is hosted on multiple servers) or cloud hosting environments, all servers may have different values of in-memory cache. So, in-memory caching cannot be used in web farm or cloud hosting environments. For thi...

#MVC #API Create and Read custom header.

Website In EmespmdHttpClient class add public void SetUserIdentifier( string userIdentifier)         {             this .DefaultRequestHeaders.Add( "EMESPMD-USER" , userIdentifier);         } From action method send _loggedInUser.XomPersonnelId as a separate param(naming userIdentifier) to each service call. In Gateway service add below line next to try{        _emespmdHttpClient.SetUserIdentifier(userIdentifier); Service Create an extension( HttpRequestExtensions ) method in EMESPMD.Api.MessageHandler folder. public static class HttpRequestExtensions     {         public static string RequestedUserIdentifier( this HttpRequestMessage request)         {         ...

#SQL Database Stuck in Restoring State

Well, if you have already restored all the database, you can execute the following code and it will bring your database from recovery to operational state. RESTORE DATABASE  NameofDatabase WITH  RECOVERY If due to any reason, above query returns error about restoring log files or any other file and you do not have that file in your hand, you can run following command. Remember above command will roll forward your database and you will be not able to restore any other database after that. RESTORE DATABASE  NameofDatabase WITH  RECOVERY , REPLACE https://blog.sqlauthority.com/2014/10/24/sql-server-database-stuck-in-restoring-state/