Monday, 29 September 2014

asp.net post xml to redirecting page



I posted an xml data from Desktop application to asp.net wep page. I can read xml at web page but if I redirect the page to another page, I get error at Desktop app. My codes are below. Thanks for help.


Desktop app:



static void Main(string[] args)
{
post();

Console.WriteLine("Post process is successed...");
Console.Read();
}

private static void post() {
System.Net.WebRequest req = null;
System.Net.WebResponse rsp = null;
try {
req = System.Net.WebRequest.Create("http://localhost:5318/Account/XMLReader.aspx");
req.Method = "POST";
req.ContentType = "text/xml";

StreamWriter writer = new System.IO.StreamWriter(req.GetRequestStream());
writer.WriteLine(getXmlData());
writer.Flush();
writer.Close();

rsp = req.GetResponse();
} catch {
throw;
} finally {
if (req != null) req.GetRequestStream().Close(); // *****Error occures here****
if (rsp != null) rsp.GetResponseStream().Close();
}
}


asp.net page code:



protected void Page_Load(object sender, EventArgs e)
{
Page.Response.ContentType = "text/xml";
System.IO.StreamReader reader =
new System.IO.StreamReader(Page.Request.InputStream);
String xmlData = reader.ReadToEnd();

Response.Redirect("/Account/Login.aspx");
}

No comments:

Post a Comment