简体   繁体   English

从HTML / Javascript发送大型String数据到背后的代码

[英]Send large String data from HTML/Javascript to code behind

Our application has some hidden fields like any other asp.net application. 我们的应用程序具有一些其他ASP.NET应用程序一样的隐藏字段。 Here we are using hidden fields to store HTML of an image, which is considerably large. 在这里,我们使用隐藏字段来存储图像的HTML,这相当大。 We use the value(large HTML string) of hidden field in our C# code for further processing. 我们使用C#代码中隐藏字段的值(大HTML字符串)进行进一步处理。

We tend to create 4 instances of our application and we have doubts over load balancing of azure cloud service. 我们倾向于创建4个应用程序实例,并且对Azure云服务的负载平衡存有疑问。 We assign values to these hidden fields in midway of our application process through javascript. 我们在应用程序中途通过javascript将值分配给这些隐藏字段。 As this processing is done on client side there are no issues here. 由于此处理是在客户端完成的,因此这里没有问题。 But since azure has multiple instances so if want to access these hidden fields on server side (ie in our C#), accessing these hidden fields directly would create any problem due to load balancing if the instance changes ? 但是由于azure有多个实例,因此如果要在服务器端(即在我们的C#中)访问这些隐藏字段,那么如果实例发生更改,则由于负载平衡而直接访问这些隐藏字段会造成任何问题吗?

Note: Our page does not postback while accessing these hidden fields on the server side. 注意:访问服务器端的这些隐藏字段时,我们的页面不会回传。

We are not clear when does the instance change, if our page does not postback then will the request go the same instance ? 我们不清楚实例何时更改,如果我们的页面没有回发,那么请求将进入同一实例吗? Is this guaranteed. 这是保证。 Also if the page does postback then does the response goes to the same instance of the calling request instance. 同样,如果页面进行回发,则响应也将转到调用请求实例的相同实例。

We need suggestions or the correct way of accessing these hidden fields on the server side. 我们需要建议或访问服务器端这些隐藏字段的正确方法。 These hidden fields are very important to us; 这些隐藏的领域对我们非常重要; using the cache/session settings of azure will become very costly for us since the data is very large. 由于数据量很大,因此使用Azure的缓存/会话设置对我们来说将变得非常昂贵。 It would be very helpful if the suggestion would be for cost free implementation. 如果该建议是关于免费实施的,那将是非常有帮助的。 As we are already running on a tight budget. 由于我们已经预算紧张。

//25Oct 2013 // 25Oct 2013

We have a large string of data, which is majorly made up of HTML obtained from Bing Map, we have taken the HTML of the Bing map using the Jquery Selector of our Bing Map div element, we want this HTML string to be sent to the code behind. 我们有一个很大的数据字符串,主要由从Bing Map获得的HTML组成,我们已经使用Bing Map div元素的Jquery Selector提取了Bing map的HTML,我们希望将此HTML字符串发送到后面的代码。 We have this string on our javascript but when we do ajax call to the code behind it fails. 我们在JavaScript上有此字符串,但是当我们对它背后的代码进行ajax调用时失败。

We even tried to send it in body via a POST method, but this fails again. 我们甚至尝试通过POST方法将其发送到正文中,但这再次失败。

 var string = formData; // so long text
        var xhr = new XMLHttpRequest();
        var body = "string=" + encodeURIComponent(string);
        xhr.open("POST", "index.aspx/getString", true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.setRequestHeader("Content-Length", body.length);
        xhr.setRequestHeader("Connection", "close");
        xhr.send(body);

As Rick suggested, we had already tried blob but the problem is with sending the string from javascript to code behind. 正如Rick所建议的那样,我们已经尝试过blob,但问题是从javascript发送字符串到后面的代码。 We are really stuck on the dead end here. 我们真的陷入了死胡同。

You indicated that caching would be costly for you. 您表示缓存对您而言会很昂贵。 While it is true that using the Cache Service would incur some costs, have you considered co-located in-role caching as an alternative? 虽然使用缓存服务确实会产生一些成本,但是您是否考虑过将主机托管在角色内缓存中作为替代选择? Perhaps you have enough extra resources on your existing instances to support your needs. 也许您在现有实例上有足够的额外资源来满足您的需求。 There is a link to some capacity planning in the link I've provided above if you choose to take this route. 如果您选择采用此路线,我上面提供的链接中有一些容量规划的链接。

--- 10/24/2013 --- -2013年10月24日-

If I'm understanding your latest description correctly, you are generating some HTML on the client that you want to upload to your web app on Azure. 如果我正确理解了您的最新描述,则说明您正在客户端上生成一些HTML,该HTML希望上传到Azure上的Web应用程序。 In the web app, you're using that HTML to generate a PDF that I assume the client would later receive. 在Web应用程序中,您正在使用该HTML生成一个PDF,我认为客户端以后会收到。 If this is your scenario, then you could just upload the HTML and store it as a blob? 如果是这种情况,那么您可以仅上传HTML并将其存储为Blob吗? This way any instance of the web app can reference it from blob storage rather than stuffing it into hidden fields. 这样,Web应用程序的任何实例都可以从Blob存储中引用它,而不必将其填充到隐藏字段中。

In your web app, you can use HttpPostedFile to receive the file from the client and save it to a blob. 在您的Web应用程序中,您可以使用HttpPostedFile从客户端接收文件并将其保存到Blob。 Note: You may need to adjust the max. 注意:您可能需要调整最大值。 size allowed for the post since it defaults to 4MB and you indicated your data could be up to 5MB. 帖子允许的大小,因为默认大小为4MB,而您表示您的数据最多可以为5MB。

I'm trying to help you but your question is just not that clear. 我正在努力为您提供帮助,但您的问题并不清楚。 Even the title is misleading given the context of the discussion. 在讨论的上下文中,甚至标题也具有误导性。 If this doesn't help, then you may want to edit your question. 如果这样做没有帮助,则您可能需要编辑问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM