RIn ASP.NET C# general method which is used to redirect from one page to another is Response.Redirect("url").
But a smart user can also navigate to a page by simply entering URL in address bar.
There may be some cases where you are not suppose to allow user to hit a page by directly entering URL.
In such cases a feasible way to implementation is use WebRequest and WebResponse
Below is simple code for above scenario.
Button event on click of which you want to jump to URL:
- protected void btnRedirect_Click(object sender, EventArgs e)
- {
- WebRequest req = null;
- WebResponse rsp = null;
- string xmlString = @"<request>Some data</request>";
-
-
- req = WebRequest.Create("URL");
- req.Method = "POST";
- req.ContentType = "text/xml";
-
- StreamWriter writer = new StreamWriter(req.GetRequestStream());
- writer.WriteLine(xmlString);
- writer.Close();
-
- rsp = req.GetResponse();
-
- }
Page load event on which the request is to be handled:
- protected void Page_Load(object sender, EventArgs e)
- {
- Page.Response.ContentType = "text/xml";
- StreamReader reader = new StreamReader(Page.Request.InputStream);
- string xmlRequestString = reader.ReadToEnd();
- XDocument doc = new XDocument.Parse(xmlRequestString);
- string reqData = doc.Root.Element("request").Value;
-
-
-
- }
In this way, the desired results can be achieved.
For any queries please do contact.
Thank you.