Pass MVC form post data to an asp page
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"]) %>
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).
精彩评论