ASP.NET
There are 9 entries for the tag
ASP.NET
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...
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...
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 ...
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...
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();
...
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...
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...
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...
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...