Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust

Ok, I could use some really expert help here. I really like using the built in WebServer.WebDev Web Server that is a part of Visual Studio 2005. For one thing, it makes getting a new developer working on Subtext (or any project) that much faster. Just get the latest code, and hit CTRL+F5 to see the site in your browser. No pesky IIS set up.

Today though, I ran into my first real problem with this approach. When running the latest Subtext code from our trunk, I am getting a SecurityException during a call to Server.Transfer.

Stepping through the code in the debugger, the page I transfer to executes just fine without throwing an exception.

Based on the stack trace, the exception occurs when the content is being flushed to the client. A security demand for Unmanaged Code is the cause of this during a call to the IHttpResponseElement.Send method of the HttpResponseUnmanagedBufferElement class.

What I don’t understand is why this particular class is handling my request instead of the HttpResponseBufferElement class? This code seems to work fine when I use IIS, so I think it’s a problem with WebServer.WebDev. Anybody know anyone who understands these internals well enough to enlighten me? I’d be eternally grateful.

I posted this question on the MSDN forums as well.

What others have said

Requesting Gravatar... DmitryR Dec 06, 2006 5:20 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
It is hard for me to say for sure without seeing the stack, but what it looks like is that calling Flush in restricted trust doesn’t work on Cassini – part of the Flush logic requires access to [internal] native response buffers and that fails with security exception under a not-full trust. Under IIS the buffers goes directly to IIS as is (no manipulation is done in managed code) and thus the security demand is not triggered.

Thanks,

Dmitry
Requesting Gravatar... Haacked Dec 06, 2006 5:41 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
I think that's exactly what's happening. It'd be nice to be able to run my web application under medium trust and Cassini under full.

Thanks Dimitry!
Requesting Gravatar... DmitryR Dec 06, 2006 7:48 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
I understand. The easiest workaround is probably to avoid calling Flush.

You could also request a hotfix from Microsoft.

Thanks,

Dmitry
Requesting Gravatar... Haacked Dec 07, 2006 7:53 AM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
Well I'm not the one calling Flush. That is being called by ASP.NET as part of the page lifecycle.
Requesting Gravatar... Kevin Dente Dec 11, 2006 12:17 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
Hey Phil. Have you reported this as a bug to Microsoft? Maybe we can get it fixed in VS2005 SP2.

Ha ha, just kidding. Odds are there will never be an SP2.

Maybe in Orcas, though.
Requesting Gravatar... Haacked Dec 11, 2006 12:42 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
I haven't but I will. Just haven't gotten around to it.
Requesting Gravatar... Haacked Dec 11, 2006 1:26 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
Ok, I reported it. Please vote on it.
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=244706
Requesting Gravatar... Kevin Dente Dec 11, 2006 2:51 PM
# re: Help! Server.Transfer Throws Exception In WebServer.WebDev In Medium Trust
Voted.

What do you have to say?

(will show your gravatar)
Please add 2 and 8 and type the answer here: