views:

62

answers:

4

Let's say I have some Classic ASP pages that produce all output via Response.Write.

I would like to port these pages over to ASP.NET, but (at least initially) avoid a total rewrite.

How should I set up my ASP.NET project to facilitate this? I assume I would have empty .aspx files and put the VB.NET/C# equivalent of the VBScript code in the codebehind file, and then use Response.Write from there?

+1  A: 

The option you describe will work.

Make sure that the .aspx pages only have a complete @page directive (with Inherits, CodeBehind and possibly language attributes) port the code and use Response.Write in the code behind.

You may want to think about porting to a more conventional asp.net application as you go along - common UI elements can be made into user controls and these can then be reused across pages.

Oded
Why only `@page` directive is a condition?
abatishchev
@abatishchev - In order to reference the code-behind.
Oded
Could you please elaborate?
abatishchev
@abatishchev - When calling an `.aspx` page, it needs to reference the code-behind with the `inherits` attribute. I don't believe the code-behind will execute otherwise.
Oded
So not only `@Page` directive is required (to use code-behind), as you say above, but also `Inherits` and `CodeBegind`/`CodeFile`
abatishchev
@abatishchev - correct. I meant a full `@page` directive with the minimum attributes for code behind to work.
Oded
A: 

Seems like an unusual thing to do but the approach you suggest should work.
However I would suggest that the effort involved in converting your vbscript to C#/VB.NET would be better spent in just rewriting as a standard ASP.NET page.

Andy Rose
+2  A: 

You can find a tutorial by scott Mitchell about how to convert ASP pages to ASP.NET this way here: http://msdn.microsoft.com/en-us/library/ms973813.aspx .

Andreas Paulsson
A: 

Here's an idea:

Since ASP.net MVC can spit out HTML from the controller you don't even need to build the .ASPX page, just the Controllers for your application.

Two ways to do it:

public ActionResult myAction() {
    Return Content("<html><body>Hello World!</body></html>");
}

And, more elegant with better performance (depending on the size of the HTML), but more work: Creating custom ActionResult for your pages:

public class MyActionResult : ActionResult
{
    public override void ExecuteResult(ControllerContext context)
    {
        context.HttpContext.Response.Write("<html><body>Hello World!</body></html>");
    }
}
Eduardo Molteni