NSilverBullet

Complex solutions for simple problems.

  • Posts in category: Web
Your Ad Here

Remember to always have a static customErrors page


Thursday 26 June, 2008 (.Net | Fixes | Ramblings | Web)

I was just surfing around on http://forums.microsoft.com and got a yellow screen of death!

msforumsyellowscreenofdeath

I must say I was slightly surprised. In web projects that I have been involved in we have always added two customErrors pages one to handle generic errors which redirects to an errorpage.aspx page and then a static html page errorpage.html which is only used when an error occurs on the dynamic error page... A sample configuration using location follows:

<configuration>

<system.web>
<customErrors mode="on" defaultRedirect="errorpage.aspx"/>
</system.web>

<location path="errorpage.aspx">
<system.web>
<customErrors mode="on" defaultRedirect="errorpage.html"/>
</system.web>
</location>

</configuration>

That way if we have a problem with our application that affects the entire site, for instance menu and navigational rendering, we can still show a nice error page with a message like "The site is temporarily unavailable, please try again in a few minutes."

Comments [0]

Your Ad Here


Java Web Service Client problems


Thursday 15 May, 2008 (.Net | Bugs | Java | Web)

I have been having some trouble lately trying to debug a .Net web service that I have constructed for a proof of concept. The scenario is that we have a Java application that calls a web service and the web service passes the call on to BizTalk for processing. Not a terribly complex scenario so I wasn't expecting much trouble setting up the POC. Unfortunately we have experienced  some really strange problems. Calling the web service from a .Net client works without problems but when the exact same SoapEnvelope is used in the Java client through a proxy we get a "HTTP/1.1 400 Bad Request" error!

How is this possible? Well after much trial and error, searching the net and generally scratching my head I finally found a clue to the root cause of the error. One of the scenarios when "400 Bad Request" is returned is if the value of the content-length header is smaller then the actual length of the message body. I could not find a simple way to get IIS 6 to log the actual HTTP headers which were received and my favourite HTTP debugger Fiddler couldn't be used when the calls came from the Java client so it was very difficult to verify. The WSE input tracing showed a correct request and the application log contained the following unhelpful message

Process information: 
    Process ID: 5856 
    Process name: w3wp.exe 
    Account name: AD\serviceaccount 
 
Exception information: 
    Exception type: HttpException 
    Exception message: Server cannot clear headers after HTTP headers have been sent. 

I managed to get a nice raw HTTP dump sent to the application log by adding the following to my Global.asax

void Application_BeginRequest(object sender, EventArgs e)
{
	//save position for reset
	long position = HttpContext.Current.Request.InputStream.Position;
	string requestBody = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();
	//reset the position
	HttpContext.Current.Request.InputStream.Position = position;
	EventLog.WriteEntry("Service HTTP Dump", Server.UrlDecode(Context.Request.Headers.ToString()).Replace("&", Environment.NewLine) + Environment.NewLine + requestBody);
}

Using this I could verify that it was in fact an incorrect content-length in the HTTP header which was causing the problem. Using Notepad++ and Fiddler I could see that the actual content-length was 634 using CRLF and 631 using only CR. The Java client was specifying 631 but the .Net web service was actually receiving 634. With the help of Telnet I could send in a call with 631 characters and CR as line-end and verify that the .Net web service handled the request properly. For the sake of clarity this is a sample Java HTTP header:

POST /path/service.asmx HTTP/1.1
Host: servername:80
Cache-Control: no-cache
Connection: close
Pragma: no-cache
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.1
SOAPAction: "http://schemas.example.com/2008/04/22/Service:ValidateRequest"
Content-Length: 631

The same request from a .Net client:

POST /path/service.asmx HTTP/1.1
Host: servername:80
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.1433)
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://schemas.example.com/2008/04/22/Service:ValidateRequest"
Content-Length: 634
Expect: 100-continue

Both requests had a length of 634.

More info on the exact nature and calculation of the HTTP headers are in the RFC and in section 3.7.1 of the RFC valid line endings for the message body are defined. Basically it says that CR, LF or CRLF should be valid as long as they are used consistently but CRLF should still be treated as two characters for content-length (the spec doesn't explicitly say that but I presume that it is required). So the .Net web service has a correct behaviour, the specification also says that content-length may be omitted in HTTP 1.1 although it should be honoured if it is specified. Since it is required in 1.0 and it is usually very easy to calculate it isn't something that you usually have to think about trying to omit and it is hidden in the web calling infrastructure of Java and .Net.

I am not sure where our error is introduced. It could be when the original message is constructed in Java, whatever library is used to calculate the content-length could do so incorrectly (not likely). A more probable source is that the message is constructed with correct line-ends in the body (CR or LF) but that the intermediary proxy recodes the call with new line-ends (CRLF) without updating the content-length.

How can we fix it? I believe that there are three possible solutions for the problem (we haven't solved it yet).

  1. Remove the proxy, should be the easiest but due to the network configuration that isn't possible at the moment.
  2. Change the way that the Java client creates it's content so that it uses CRLF by default thereby forcing a correct larger content-length.
  3. Use the Application_BeginRequest method in Global.asax or an HTTPHandler to somehow rewrite the input stream or recalculate the content-length. At the moment I am not sure that either is possible.

Update

We managed to remove the proxy (which was actually part of a VPN connection) and our troubles disappeared.

Comments [0]


New Theme for dasBlog - now with Google Search


Wednesday 14 May, 2008 (Blogging | dasBlog | Web)

I have created a new theme for my blog, I feel that this theme is more modern and has a lighter feel to it. I based the theme on an open source / free web template named Multiflex. It is available from www.1234.info this theme is based on Multiflex version 5.4. It took a lot more time to convert the web template into a dasBlog theme than I had figured on - partly because i also changed the page width of Multiflex which meant that I had to redo all the border images and partly due to Multiflex being gray only and I had to go through all the CSS to restyle the entire template! I am pretty pleased with the end result at the moment, although I am sure there are a couple of glitches that will need to be ironed out. One thing that irritated me with dasBlog and theme modifications is that it doesn't seem to be possible to change how certain parts are rendered for example post comments and related links. A lot of the content gets put in tables and modern design doesn't use tables but advanced CSS for positioning and flow control.

I can whole-heartedly recommend Multiflex to anyone who wants to create web pages but, like me, is not super gifted in the arts department! The template is well documented, there is a content toolkit for building your page structure and the CSS was easy to understand and modify. I found it at www.openwebdesign.org there is also a Color Contest there which I will check in on in the future to see how my color scheme compares to others. I used a flash-based tool from www.colorsontheweb.com to create a pleasant color scheme, it was a great help since I am not that good at picking out matching colors.

One major addition in this theme for my site is the Google search box in the top right-hand corner. Originally I tried to just add the Google search code in my old theme but since the Google code contains a <form> element it conflicts with the predefined form in dasBlog/ASP.Net. I solved it by placing the Google form in a separate html file and just including that file as an iframe.

Comments [1]


Getting aggregator pings to work with medium trust


Tuesday 15 April, 2008 (.Net | Blogging | Bugs | Fixes | Web)

I seem to have managed to get server pings from dasBlog to work in medium trust! This has been a major issue for me previously, not as much of an issue now that I primarily use off-line tools but it is still great to have it. The key is that originUrl in the medium trust settings supports regular expressions! More info on Haacked, which is where I found the solution. Just to make things clear:

<trust level="Medium" originUrl=".*" />

will allow your web site to send web requests to any external site...

Comments [1]


Strange ASP.NET Web Parts database exception.


Monday 04 February, 2008 (.Net | Bugs | Fixes | Web)

Recently I was working on ASP.Net 2.0 Web Parts in a Virtual PC environment and ran across a strange exception. I had read that the Web Parts personalization database is separate from the membership and profiles databases but had not really thought about it further. Previously everything just seemed to work once I ran "aspnet_regsql" to create the aspnetdb database to handle all the data for the services.

In the VPC there was already a really simple Web Part Page that I wanted to test. I had not prepared the VPC myself and others had been using it before me (so I presumed that it would work) but no one had used it in a long while. When I attempted to login and access the Web Part page I received this exception:

Procedure or Function 'aspnet_PersonalizationPerUser_GetPageSettings' expects parameter '@TimeZoneAdjustment', which was not supplied.

I checked the aspnetdb database to see if there was something wrong there but the stored procedure did not contain a '@TimeZoneAdjustment' parameter... Some related forum discussions on the web indicated that it might be a problem with the solution and database being created under a pre-release version of .Net 2.0. I tried re-running aspnet_regsql to remove and recreate the aspnetdb database, I reinstalled .Net 2.0, I installed SP1 for .Net 2. Nothing helped.

It turns out that the default personalization provider for Web Parts uses a file based SQL Express database which is automatically created in the App_Data folder of the web application. This database had already been created using a previous version of the framework before I started looking at the solution. For the sake of confusion it is also named aspnetdb, removing this database from the App_Data folder solved the problem. When I logged in and opened the Web Part page the database was recreated with the correct structure and everything just worked!

Comments [0]


Talk on Migrating ASP.NET 1.x to ASP.NET 2.0 at DevDays 2006


Thursday 07 December, 2006 (.Net | Speaking | Tips | Web)

A couple of days ago I did my first big talk, a colleague and I held a 50 minute session on migrating from ASP.NET 1.x to ASP.NET 2.0 at DevDays 2006 in Stockholm. Luckily it was a big success! I credit our success almost entirely (obviously we had some part in it...) to Scott Hanselman, we found many tips and links on the topic of public speaking on Scott's blog. The most important tip and what we worked on most was "be prepared", we studied our subject vigorously the days before, preparing for any questions that the audience might ask. We also practised our talk, including all the demos, about 6 or 7 times to get the timing right and just feel confident with the content.

In order to Google-boost these great resources and to make it easier for myself to find them again I list them here:
http://www.hanselman.com/blog/content/radiostories/2003/01/22/scottHanselmansTipsForASuccessfulMsftPresentation.html
http://www.hanselman.com/blog/PresentationTipsPPT.aspx
http://www.hanselman.com/blog/PowerPointTipsBeyondBullets.aspx
http://www.toastmasters.org/pdfs/top10.pdf
http://sociablemedia.typepad.com/beyond_bullets/
http://www.venkatarangan.com/blog/PermaLink.aspx?guid=dab57735-2976-40d7-a5d0-2e641ddea515
http://www.presentationzen.com/
http://www.hanselman.com/blog/InSearchOfThePerfectMonospacedProgrammersFontInconsolata.aspx
http://www.hanselman.com/blog/ReadySetVSNETChrisKinsmanAHrefhttpwww.aspx
http://www.hanselman.com/blog/PresentationTipsForPeopleRunningVirtualPCOrVMWare.aspx
http://www.hanselman.com/tools

Comments [0]


Migrating Asp.Net 1.1 to .Net 2.0 - DevDays 2006


Wednesday 29 November, 2006 (.Net | Speaking | Web)

I will be speaking at DevDays 2006 here in Sweden next week on the topic of migrating Asp.Net 1.1 applications to Asp.Net 2.0. It is an interesting topic especially when you really start looking under the covers at what has changed at a lower level. The whole session will be recorded and may be made publicly available at a later date.

For anyone else who is interested in this topic these are some of the resources I have used for my presentation:
What's New in ASP.NET
ASP.NET 2.0 Internals
Codebehind and Compilation in ASP.NET 2.0
Master Pages in ASP.NET 2.0
Understanding Page Inheritance in ASP.NET 2.0
Migrating from ASP.NET 1.1 to ASP.NET 2.0

Comments [0]


HTML visualizer


Tuesday 28 November, 2006 (Geek | Web)

I found a cool applet online that creates a graphical tree structure of any website. This is the first page of nSilverBullet on the 28th November 2006:

blue: for links (the A tag)
red: for tables (TABLE, TR and TD tags)
green: for the DIV tag
violet: for images (the IMG tag)
yellow: for forms (FORM, INPUT, TEXTAREA, SELECT and OPTION tags)
orange: for linebreaks and blockquotes (BR, P, and BLOCKQUOTE tags)
black: the HTML tag, the root node
gray: all other tags

You can try it out here: HTML DOM visualizer

Comments [0]


What is Web 2.0.


Monday 27 November, 2006 (Business | Ramblings | Web | Web2.0)

Since I have been working on WinForm applications and technical infrastructure projects (yeah real sexy!) for the last year and a half I have not really paid much attention to the whole Web 2.0 debate and hype. Recently I have started to look at web projects again and I came across a good, short explanation of where the money is in Web 2.0 and how it is different from Web 1.0. Now I understand why Google bought YouTube for $1.65 bn, if you do the math then it turns out that they really didn't pay that much per user and each user of YouTube contributes value to the whole.

Basic (flawed) Web 2.0 definition by me: web as a platform for user interaction using data collection and aggregation as the driving force. There is a full explanation on Wikipedia but Ajits blog post made it much clearer for me.

I believe that most of the cause of the Dot Com crash can be derived from the differences between Web 1.0 and 2.0. Most companies and individuals back then failed to realise that the web was an extension of their physical business. We thought that we were building Web 2.0 but we were just extending the reach of our existing business onto the Internet. The Web 1.0 failures that I have seen up close were caused by insufficient logistical support in the physical business, we still need all the infrastructure and logistics of a book store if we want to be Amazon. During the Dot Com Hype we thought that getting the visitors and the orders would automatically solve all our other problems, well they didn't! Web 2.0 is the approach that we should have been using... Get rid of the physical product, use the enabling of social interaction as the value you provide to your users and also as the value that you create. Find someone who either wants to target your users for advertising (Google), wants to partner with you for selling related products (YouTube) or who can use the data that you provide as input into their business (Swedish Lunar Storm).

Comments [0]


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Sign In