开发者

ASP.NET page using only Response.Write

开发者 https://www.devze.com 2023-01-14 09:39 出处:网络
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.

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 proj开发者_JS百科ect 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?


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 .


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.


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.


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>");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消