Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
posts - 96, comments - 70, trackbacks - 0

ASP.NET

There are 9 entries for the tag ASP.NET
A better Visual Studio 2008 Development Server test fixture

  download the VS2008 solution here Introduction In a previous post I presented a class that enables the programmatic control of Visual Studio 2008 development server, WebDev.WebServer.exe. This use case for this functionality as presented here is in the interest of testing web applications and endpoints. Refactored While the previous implementation is capable in the context of interactive test runners, there were a few resource management issues affecting the usability in more autonomous scenarios such as continuous integration. Amongst these were the use of static port assignment and the lack of a means to shut down an instance, specifically the ability to start and stop an instance...

posted @ Saturday, April 17, 2010 4:46 AM | Feedback (1) |

Deserializing MS Ajax ClientScript JSON in managed code revisited. e.g. {"d":{"__type":

Overview In a previous post, I proposed a means of deserializing JSON returned from calls to ClientScript endpoints such as XML WebServices decorated with [ScriptService] or [ScriptMethod] attributes, Ajax-enabled WCF Services and WCF services created with WebScriptServiceHostFactory. The use case that prompted this requirement is testing endpoints called by client-side JavaScript. Calling WebScript enpoints in managed code using HttpWebRequest is easy, the trick is to specify content-type 'application/json'. And this is where the problems start. Problem Domain When a WebScript endpoint responds to a request with content-type 'application/json' it understandably assumes that it is being called from JavaScript and, as of 3.5sp1, wraps the actual...

posted @ Tuesday, April 13, 2010 4:44 AM | Feedback (1) |

C# File Upload with form fields, cookies and headers

In it's most basic form, uploading a file or other data to an http form handler using managed code is quite simple using the System.Net.WebClient class. Listing 1: SimpleWebClientUpload public void SimpleWebClientUpload() { string filePath = Path.GetFullPath("TestFiles/TextFile1.txt"); var client = new WebClient(); client.UploadFile("http://localhost/myhandler.ashx", filePath); }   It is a common case that some cookies need to be maintained between requests or perhaps a header needs to be added to the request.  This is possible using the WebClient class but the technique is not immediately obvious. The trick is to create a class that inherits WebClient ...

posted @ Monday, April 12, 2010 11:52 AM | Feedback (1) |

A general purpose Visual Studio 2008 Development Server (WebDev.WebServer.exe) test fixture

   UPDATE: This post is valid as reference information, but an improved version of the code presented can be found here.     While I generally use CassiniDev for smoke testing, sometimes a quick and simple way to run some tests against a site using the built in server comes in handy. Spinning up an instance of WebDev.WebServer.exe is fairly simple. The executable can be found at C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe (Program Files (x86) for x64 Windows). If you invoke the .exe with no arguments you will see the usage document listed below. Listing 1: WebDev.WebServer Usage --------------------------- ASP.NET Development Server --------------------------- ASP.NET Development Server Usage: WebDev.WebServer /port:<port number> /path:<physical path> [/vpath:<virtual path>] port number: [Optional] An...

posted @ Sunday, April 11, 2010 4:15 PM | Feedback (0) |

Preventing caching of content in ASP.Net Pages and other HttpHandlers

  Sometimes I forget to squash caching on my JSON handlers and end up with odd runtime behavior, especially when using IE. You can ensure that each request actually pulls data instead of hitting the cache by adding this to the top of a handler (.ashx) or in the page_load of a .aspx. Drop 'context.' for use in page_load.   context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetNoStore();   This is what the head of my JSON handlers typically look like: public void ProcessRequest(HttpContext context) { context.Response.ClearContent(); ...

posted @ Tuesday, March 23, 2010 2:59 AM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Testing and Parsing an ASP.NET YSOD (Yellow Screen Of Death) from an XMLHttpRequest.responseText

  After a minor bout of forgetfulness regarding legal regexp flags in Javascript, I knocked this one out that parses the comment block at the end of an YSOD.   var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*[\n\r]*)*?)\s*(at(.*[\n\r]*)*)-->/; if (rxYSOD.test(text)) { // looks like one.. var ysod = rxYSOD.exec(text); errObj = { Message: ysod[2], StackTrace: ysod[4], ExceptionType: ysod[1] }; } will find and parse the comment block shown. I am guessing that is why they put it there....   <html> <!-- omitted --> <body bgcolor="white"> <!-- omitted --> </body> </html> <!-- [ArgumentException]: Unknown web method ValidateUser. Parameter name: methodName at...

posted @ Saturday, February 27, 2010 11:46 PM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Salient.Web.Security.AccessControlModule

download source code and demo download this article in .doc format Overview I a previous article I complained about the lack of a true 403 Forbidden error in ASP.NET and the clumsy way that authentication is handled by FormsAuthenticationModule. The solution I came up with was a good first attempt but, in my opinion, came up short. Particularly when handling authentication of requests that ScriptModule touches. So I decided to take another swing at it, this time with some ammunition. I took the list of HttpModules from the root Web.config and the ScriptModule that is added to ASP.NET 3.5 web apps and dove in with...

posted @ Monday, August 17, 2009 10:18 PM | Feedback (1) |

Exploring Web.config - system.web/httpModules

download this document in .doc form HttpApplication Events, the HttpModules that handle them and in what order: It is a generally held opinion that to depend upon the order of module/event execution is bad practice and produces brittle code.  I agree somewhat with the spirit of the opinion but not at all with the explicit reason. Events and Collections are not magic bags that arbitrarily insert handlers/items in some random order. I think, in a general sense, that to depend on event handler execution order is a 'bad idea' is valid. In a more specific context, in which the enviroment is known and...

posted @ Sunday, August 16, 2009 11:31 AM | Feedback (2) |

Consuming ASP.net WebServices, WCF Services and static Page methods from JavaScript (sans MS AJAX)

download sample code Overview The Microsoft ASP.NET AJAX platform, known previously as ATLAS and ASP.NET 2.0 AJAX Extensions and fully rolled into ASP.NET 3.5, offers rich functionality but in certain scenarios the the required .ASPX client page and ScriptManager control coupled with the Microsoft Ajax library may conflict with existing requirements or present unnecessary overhead. This document will illustrate that it is possible to leverage the full power of the ASP.NET platform from client script with just a few lines of javascript code on an HTML page. Caveats: This document will not attempt to illustrate a robust...

posted @ Saturday, August 15, 2009 11:04 AM | Feedback (5) |

Powered by: