Archive for the ‘Microsoft.NET’ Category

HTTP Status/Error Code: Quick Reference

May 6, 2008

 

During your HTTP sessions, you’ll receive various numbered codes from Web servers.  When connected via HTTP, displays these codes in the log window.  Some codes represent errors.  Most others simply communicate the status of the connection. Here are brief explanations for the most common status and error codes.

 

 

Error or Status Code

Description

100 Series

Informational - These status codes indicate a provisional response. The client should be prepared to receive one or more 1xx responses before receiving a regular response.

100

Continue.

101

Switching protocols.

200 Series

Success - This class of status codes indicates that the server successfully accepted the client request.

200

Okay - The client request has succeeded  This status code indicates that the Web server has successfully processed the request

201

Created.

202

Accepted.

203

Non-authoritative information.

204

No content.

205

Reset content.

206

Partial content.

300 Series

Redirection - The client browser must take more action to fulfill the request. For example, the browser may have to request a different page on the server or repeat the request by using a proxy server.

302

Object moved.

304

Not modified. The client requests a document that is already in its cache and the document has not been modified since it was cached. The client uses the cached copy of the document, instead of downloading it from the server

307

Temporary redirect.

400 Series

Client Error - An error occurs, and the client appears to be at fault. For example, the client may request a page that does not exist, or the client may not provide valid authentication information.

400

Bad request.

401

Access denied.

403

Forbidden.

404

Not found. This error may occur if the file that you are trying to access has been moved or deleted.

404.0

File or directory not found.

404.1

Web site not accessible on the requested port.

405

HTTP verb used to access this page is not allowed (method not allowed).

406

Client browser does not accept the MIME type of the requested page.

407

Proxy authentication required.

412

Precondition failed.

413

Request entity too large.

414

Request-URL too long.

415

Unsupported media type.

416

Requested range not satisfiable.

417

Execution failed.

423

Locked error.

500 Series

Server Error - The server cannot complete the request because it encounters an error.

500

Internal server error.  You see this error message for a wide variety of server-side errors.

500.12

Application is busy restarting on the Web server. Indicates that you tried to load an ASP page while IIS was in the process of restarting the application. This message should disappear when you refresh the page. If you refresh the page and the message appears again, it may be caused by antivirus software that is scanning your Global.asa file.

500.13

Web server is too busy.

500.15

Direct requests for Global.asa are not allowed.

500.16

UNC authorization credentials incorrect. This error code is specific to IIS 6.0.

500.18

URL authorization store cannot be opened. This error code is specific to IIS 6.0.

500.100

Internal ASP error. You receive this error message when you try to load an ASP page that has errors in the code.

501

Header values specify a configuration that is not implemented.

502

Bad Gateway.  Web server received an invalid response while acting as a gateway or proxy. You receive this error message when you try to run a CGI script that does not return a valid set of HTTP headers.

503

Service unavailable. This error code is specific to IIS 6.0.

504

Gateway timeout.

505

HTTP version not supported.

 

 

 

 

.NET Performance tips on using Strings

April 30, 2008

Here is an interesting tech analysis on String in .NET.    Rico Marains .NET Blog gives wonderful analysis of internal process. Excerpt is copied from his blog for first reading. I suggest you to read his blog worths lot. 

“Recently there was a discussion on one of our internal email aliases in which this problem came up. I though it was an interesting problem so I posed this Quiz to assorted people I work with to see what kinds of things they would say.

Considering these three options:

Option 1:

sw.WriteLine(subject + “: ” + message);

Option 2:

sw.WriteLine(”{0}: {1}”, subject, message);

Option 3:

sw.Write(subject);
sw.Write(”: “);
sw.WriteLine(message);

Answer these questions:

Q1. Which of these choices offers the best performance?
Q2: Can you characterize the memory usage of each of these?
Q3: Which would the performance team generally recommend, and why?
Q4: What special factors might alter this recommendation?
Q5: What did you have do assume about “sw” to answer the question?

I encourage you to think about this for a few minutes (more is good too) before reading past the line. SPOILERS/ANSWERS follow.


For everyone that took the time to think about this at all, thank you very much.In the course of my job I’m often asked to comment of the probable performance of an assortment of solutions to give guidance, or at least suggest what measurements should be made. So I approached this quiz the same way and made my best guesses/recomendations as I would if I could not do the measurements. Then I went back and did the actual measurements.

Here are my own answers:

Q1. Which of these choices offers the best performance?

  • Only thing I can say for sure is that #2 will lose to #1 in all cases
  • #3 is going to be best if the output is buffered
  • #1 is going to be best if the output is unbuffered
  • In any case, a typical program’s overall performance will be unaffected by the choice

Q2: Can you characterize the memory usage of each of these?

(These answers all proved to be “close but no cigar” due to the unusual WriteLine behavior discussed in the real analysis, see below)

All three probably have allocations associated with buffering the stream, ignoring those as invariant, the allocations unique to each choice are:

#1 single concat operation, one temporary string
#2 assorted allocations, including string builder, underlying string buffer, vararg array (I was close)
#3 no allocations

Q3: Which would the performance team generally recommend, and why?

Even though it’s the worst performing, and we knew that much in advance, both of your CLR Performance Architects concur that #2 should be the default choice. In the highly unlikely event that it becomes a perf problem the issue is readily addressable with only modest local changes. Normally you’re just cashing-in on some nice maintainability. We do not alter our choice given the data below.

Q4: What special factors might alter this recommendation?

Specific measurements indicating that the code path had become a hotspot.

Q5: What did you have do assume about “sw” to answer the question?

Only that the stream did not have exotic behavior (such as weird cryptographic features that make the cost model very complex) and that it was buffered. In the event of an unbuffered stream of one type or another there are signficant semantic differences between (1 or 2) and (3) and potentially huge perf differences too.

OK, time to see how we did.

To do the analysis below I used the following benchmark program and CLR Profiler, which is one way to look at this data.

namespace Test
{
    using System;
    using System.IO;
 
    class Test
    {
        static private String s1 = “Hello”;
        static private String s2 = “Good bye”;
        static private int iterations = 5;
        static private volatile int foo = 0;
 
        static private MemoryStream ms = new MemoryStream(100000);
        static private StreamWriter sw = new StreamWriter(ms);
 
        public static void Main(string[] args)
        {
            int i;
 
            for (i=0;i<iterations;i++) Test1();
            for (i=0;i<iterations;i++) Test2();
            for (i=0;i<iterations;i++) Test3();
        }
 
        public static void Test1()
        {
            sw.WriteLine(s1+”: “+s2);
            foo++;
        }
 
        public static void Test2()
        {
            sw.WriteLine(”{0}: {1}”, s1,s2);
            foo++;
        }
 
        public static void Test3()
        {
            sw.Write(s1);
            sw.Write(”: “);
            sw.WriteLine(s2);
            foo++;
        }
    }
}

The results below are in the form of an execution trace showing functions and allocations for each of the three options as reported by CLRProfiler”. Continued here

ASP.NET state management

April 30, 2008

ASP.NET offers a number of places to store state, both on the client and server. However, sometimes it’s difficult to decide where you should put things and how to make that decision.

You choices for state management include:

  • Application - Stored on the server and shared for all users. Does not expire.  Deprecated by Cache (below).
  • Cache - Stored on the server and shared for all users. Can expire.
  • Session - Stored on the server.  Unique for each user.  Can expire.
  • ViewState - Stored in a hidden page input (by default).  Does not expire.
  • Cookies - Stored at the client. Can expire.
  • QueryString - Passed in the URL.  Must be maintained with each request.
  • Context.Items - Only lasts for one request’s lifetime.

HowTo: Implement IPersistStream in a .NET class

April 22, 2008

When writing customized objects, many cases need to support serialization. For example, a custom symbol or element needs to be saved with the map document and load when the map document is opened. This functionality is available by implementing the interface IPersistVariant.

To support cloning through serialization, temporarily save the object to an ObjectSteam and then duplicate the object by creating a new instance of the class and loading its properties from the temporary ObjectStream. use an ObjectCopy class, which uses ObjectStream internally. This class requires that the cloned object, or clonee, support IPersistStream.

IPersistStream is a Microsoft interface which provides methods for saving and loading objects that use a simple serial stream for their storage needs. In order to use the structured stream given by these methods using .NET, the objects must be converted into a byte array.

There are several ways to convert objects into byte arrays in .NET, however each method is object type specific. For objects that only have managed class members, use MemoryStream in conjunction with a BinaryFormatter, assuming that all of these members support serialization. The reality is that the object has different types of class members, including both managed and unmanaged types, i.e., ArcObjects components. This makes it a challenge to implement the IPersistStream .Save() and IPersistStream.Load() methods. Writing this code as a part of the custom object can also be cumbersome and difficult to read and maintain.

The solution is to write a helper static class with helper methods Save() and Load () to delegate the calls when implementing IPersistStream in an object.

Further reading…

Sample for  ’Serialization ArcObjects to memory ’

MapObjects and Visual Studio compatability

April 10, 2008

MapObjects 2.2 was designed, tested, and supported for use with Visual Studio .NET (from 2002), which uses the .NET Framework v1.0. Unfortunately, it is not supported for use with Visual Studio 2005, which uses the .NET Framework v2.0. It may just work, but we have not tested it. For one, the MapObjects installer only knows how to look for the version 1.0 GAC, so at a minimum, you would have to do part of the installation manually, depending on how comfortable you are with modifying the development environment and the .NET framework.

Even the most recent version of MapObjects-Windows Edition, version 2.4 does not support Visual Studio 2005.

It is unfornuate that ESRI will end MapObjects Supports soon and discontinue the product.

ESRI Code Challenge Results!

March 25, 2008

Dear ESRI Devleopers,

Its time to congratulate  the winners of the 2008 ArcGIS Server Code Challenge contest

First Place: $15,000

Display Geospatial Analysis results in Google Maps and Microsoft Virtual Earth with ArcGIS Server

John Waterman, Vice President of Geospatial Solutions, East Burke, Vermont, USA

Second Place: $7,500

ArcGIS Server Virtual Earth Tile Server

Dave Bouwman, Senior Software Architect, Data Transfer Solutions (DTS), Fort Collins, Colorado, USA

Third Place: $2,500

SDE Web Catalog

Loganathan Vijay Sambandhan, GIS Developer, Buffalo, New York, USA

Honorable Mention

Google Maps Adapter to ArcGIS Server Map Cache

Nianwei Liu, Senior System Analyst Programmer, Charlotte, North Carolina, USA

Precompile ASP.Net web application: ESRI Tech Article

March 19, 2008

 Summary

Compiling takes a long time the first time when using ArcGIS Server Manager or the ArcIMS Web Manager if you have created ASP.Net web application.Microsoft .NET Framework provides a command line tool to precompile ASP.Net applications to avoid the initial wait time.Instructions provided describe how to use the tool with respect to web applications created using the Web Manager.

Procedure

There are two options to precompile:a. Provide the virtual directory, assuming that the application has already been deployed in IIS.b. In the case that the web application is not yet deployed or if not using IIS as web server, provide the physical path to the web application.

The following procedure is for the first case since when using the manager the applications are typically deployed in the web server.

  1. Start a command prompt and navigate to the .NET Framework directory. For example:
    cd "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727"
  2. Run the following command:
    aspnet_compiler -v /USABaseMap

 There are several useful switches that can be specified. See the links in the Related Information section below for further reference.The above example precompiles for a web application called ‘USABaseMap’ which is created using ArcGIS Server Manager at the IIS Webserver root directory, typically located at ‘c:\inetpub\wwwroot’.

Related Information

SOME GIS BOOKS

February 27, 2008

Here are some books on GIS application development which I recently came across on surfing. Here are the details.

Programming ASP.NET for ArcGIS Server (English) - (ISBN: 9781418018757)

Web Mapping Illustrated Using Open Source GIS Toolkits

Beginning MapServer: Open Source GIS Development

Personally, I haven’t read any of these books listed above. If anyone has free copy (e-book) pl pass it on :)

Initialize ArcObjects in standalone applications

February 15, 2008

Very often, we forget to intialise product license when we develop standalone apps using Arcobjects. Here is link to understand license model and IAOInitialize interface usage.

AoInitialize Interace

ArcGIS License Mode

ArcGIS Server 9.2 .NET Installation

February 12, 2008