Why does the behavior of Response.Write change in this scenario?

When I POST to a page using the following code, Response.write (โ€œHeyโ€) does not write the content (โ€œHelloโ€) to the parent page

<form method="post" name="upload" enctype="multipart/form-data"
action="http://localhost:2518/Web/CrossPage.aspx" >
<input type="file" name="filename" />
<input type="submit" value="Upload Data File" name="cmdSubmit" />
</form>

But when I use the following code and POST data, Response.write ("Hey") can be obtained on the parent page

 HttpWebRequest requestToSender = (HttpWebRequest)WebRequest.Create("http://localhost:2518/Web/CrossPage.aspx");
 requestToSender.Method = "POST";
 requestToSender.ContentType = "multipart/form-data";

 HttpWebResponse responseFromSender = (HttpWebResponse)requestToSender.GetResponse();
 string fromSender = string.Empty;

 using (StreamReader responseReader = new StreamReader(responseFromSender.GetResponseStream()))
    {
        fromSender = responseReader.ReadToEnd();
    }

In CrossPage.aspx, I have the following code

 if (!Page.IsPostBack)
    {
        NameValueCollection postPageCollection = Request.Form;

        foreach (string name in postPageCollection.AllKeys)
        {
            Response.Write(name + " " + postPageCollection[name]);
        }

        HttpFileCollection postCollection = Request.Files;
        foreach (string name in postCollection.AllKeys)
        {
            HttpPostedFile aFile = postCollection[name];
            aFile.SaveAs(Server.MapPath(".") + "/" + Path.GetFileName(aFile.FileName));
        }

        Response.Write("Hey");
    }

I have no code in the Page_Load event of the parent page.?

What could be the reason? I need to write โ€œheyโ€ on the parent page using the first script. Both applications have a different domain.

Edit: "Hello" will be from CrossPage.aspx. I need to write this to the parent page

, Page_Load() CrossPage.aspx, URL " http://localhost:2518/Web/CrossPage.aspx", , CrossPage.aspx .

+3
5

:

, Page_Load() CrossPage.aspx, URL " http://localhost:2518/Web/CrossPage.aspx", , CrossPage.aspx .

CrossPage.aspx, , .

, - . AJAX, : ?

+1

, aFile.SaveAs(Server.MapPath( "." ) + "/".... . .

UPDATE:

, HttpWebRequest, , , . HTML , . , ,

, , try catch, , exception, , . , . - exception.

ur, "/" @"\". Server.MapPath(".") , , .

0

, , if (!Page.IsPostBack) ? , .

(HttpWebResponse)requestToSender.GetResponse(); GET, , Crosspage.aspx .

0

. . ParentPage.aspx > ServicePage.aspx > ParentPage.aspx .

#, , . , #. Winform. NimsDotNet, "get" , CrossPage.aspx .

, " ". , , IIS. # - scenerio, . Response.Write() fromSender. , . , , javascript .

This post shows you how to make a query using jQuery.

0
source

I would suggest changing CrossPage.aspx to .ashx HttpHandler. The page.IsPostBack file may not work correctly because it expects the ViewState and other hidden fields of the ASP.net form to tell it that this is a message from the ASP form. You also do not need to go through all the functionality of the page life cycle that passes through ASP.net web forms.

0
source

Source: https://habr.com/ru/post/1750280/


All Articles