1

We are doing a old section reskin which is written in classical asp and it is being remade in Asp.net MVC. Content of some of the pages just needs to be pulled into a new layout. So I have written a helper method that basically reads asp file and renders contents in the current view.

public static string readHtmlPage(string url)
        {

             try
            {

            string host = HttpContext.Current.Request.Url.Host;

            url = "http://" + host + url;

            WebResponse objResponse;

            WebRequest objRequest = System.Net.HttpWebRequest.Create(url);

            objResponse = objRequest.GetResponse();

            StreamReader sr = new StreamReader(objResponse.GetResponseStream());

            return sr.ReadToEnd();

            }
                catch (Exception ex)
            {
                return "If include file cannot be found you will see this message. This is temporary:" + url;
            }
        }

and its great and works for majority of the pages event when I have to pass the query strings in the urls.

However I have a contact.asp page that is a form that posts to itself to do the validation before sending the e-mail or whatever it does.

Is there a way I can just have it post to the mvc and then pass it the post data?

Currently I am doing this for pages that I need to pass some info to

 <%=IncludeHelper.readHtmlPage("/press_room/recent.inc.asp?type="+ ViewData["type_id"]) %>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Boris Smirnov
  • 1,217
  • 4
  • 15
  • 27
  • I can't recommend this way of "including" content. Why not just use an IFrame for pieces that you can't rebuild in MVC? Making a web request from MVC to another web server to render content seems inefficient, and you're asking for trouble for form scenarios. – calebt Oct 14 '09 at 14:52
  • actually it is on the same server so it is somewhat like doing server side include. I do not particularly like it myself but under the circumstances this is what I have to do to meet the requirements and deadlines. – Boris Smirnov Oct 14 '09 at 17:33
  • No, it isn't anything like doing a SSI. While you don't have any network latency in this case, you are still making a http request and rendering the response into your stream, blocking threads on your server the whole time. At least cache it man. – Wyatt Barnett Oct 14 '09 at 23:22

1 Answers1

1

When you grab the StreamReader of contact.asp, there's nothing about that page that is classic ASP anymore--it's just HTML. So, you could change the form action to post to, for instance, an MVC controller's action, and then parse the form data there (probably you'll need to use good-old fashioned response.redirect to do this, depending on contact.asp's form input names).

You'll need to parse the HTML content from the StreamReader in order to do this, which might be trivial, or might be difficult, depending on the markup.

Additionally, you'll need to duplicate the validation functionality and the email/persistence functionality in the MVC app (which good practices say should be in your model, so you'll need to duplicate the model of your ASP app too, if you have one).

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
  • this would not make sense for me in this case, because if I am going to duplicate validation functionality, I might as well redo the whole form to work under mvc. Thank you for your input though. – Boris Smirnov Oct 16 '09 at 14:44
  • well you could also pass the form to the MVC action AFTER the validation--this would require you to change the code in the classic ASP page to do a server.transfer or xmlHttp request (http://stackoverflow.com/questions/381596/asp-equivalent-of-curl-not-asp-net) – Matthew Groves Oct 16 '09 at 18:05