我正在尝试将大型excel文件发送到其余服务(使用servicestack).
客户端和服务器(Servicestack服务)应用程序部署在不同的服务器上.
我在客户端使用以下代码上传excel文件(8 MB大小)
取自
http://www.codeproject.com/Articles/501608/Sending-Stream-to-ServiceStack
HttpWebRequest client = (HttpWebRequest)WebRequest
.Create(ConfigurationManager
.AppSettings["applicationUrl"]
+ @"/servicename/"
+ fileUpload.FileName
+ @"/" + FileType + @"/"
+ Utility.UserName + @"/"
+ Utility.EmployerID + @"/"
+ UploadedFrom);
client.Method = WebRequestMethods.Http.Post;
////the following 4 rows enable streaming
client.AllowWriteStreamBuffering = false;
client.SendChunked = true;
client.ContentType = "multipart/form-data;";
client.Timeout = int.MaxValue;
// client.KeepAlive = false;
//client.ProtocolVersion = HttpVersion.Version10;
//client.ContentLength = 0;
//client.Timeout = Timeout.Infinite;
//client.AllowWriteStreamBuffering = true;
Stream stream = fileUpload.InputStream;
if (stream.CanRead)
{ stream.Copy(client.GetRequestStream());
}
var response …Run Code Online (Sandbox Code Playgroud) 以下是上下文:
ASP MVC3 - IIS 7
我正在使用ElMah配置得很好,因为MVC几乎无处不在.它正在发挥作用.
这是我在配置文件中的内容
<system.web>
<httpRuntime maxRequestLength="1024" enableVersionHeader="false" />
<customErrors mode="On" defaultRedirect="~/Error/Generic" />
...
<system.webServer>
<httpErrors errorMode="Detailed" existingResponse="PassThrough" defaultPath="~/Error/Generic" defaultResponseMode="ExecuteURL"></httpErrors>
Run Code Online (Sandbox Code Playgroud)
现在这是我的问题我花了整整一天试图捕获这个错误:当我提交超过1024字节的文件时"超出最大请求长度"
在asp错误和IIS错误之间,有时IE拦截,我变得疯狂,我无法理解为什么这么复杂.我已经尝试过这些解决方案,没有一个能为我 解决方案1 解决方案2
谢谢您的帮助
我正在为我的.net MVC 5网站制作相册功能,最近我遇到了一个问题,默认情况下.net将文件上传限制为4 MB.
不想再次遇到这个错误,我很想把它设置为像1 GB这样大的东西.但这似乎是一个坏主意.我有3个问题:
如果我将文件上传最大长度设置为1 GB,我会打开哪些安全漏洞?
有人建议我只增加上传到特定目录的文件上传长度.这实际上更安全了吗?
在.net中,如果我限制POST,GET或所有请求的长度,则配置文件不是特定的.我认为这个限制适用于所有请求?
我基本上有一个ASP.NET FileUpload控件,我需要为其提供以下消息抛出的异常:
超出最大请求长度.
限制是我需要限制用户上传一个文件,因为我已将其他详细信息从一些文本框保存到DB中.
最大文件大小设置在web.config中设置如下:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="41943040" />
</requestFiltering>
</security>
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="40960" requestValidationMode="2.0" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
因此我搜索了许多解决方案,如下所示:
使用Global.asax验证"Application_BeginRequest()"中的文件大小,但它没有解决我的问题,当文件大小较大且重定向到错误页面不起作用时,它在重定向时崩溃.
使用AjaxFileUpload而不是ASP.NET FileUpload控件,这在文件大小检查时再次崩溃,大于Web.config中允许的最大大小.其次我必须限制总共用户只能上传一个文件,而不是一个文件,所以使用AjaxFileUpload它不能正常工作,因为我必须上传一个文件并将其他细节保存在一些文件中与该文件相关的文本框.第三,当文件大小超过限制(即40MB)时,AjaxFileUpload只会变为红色,不会显示任何消息.
我想知道我怎样才能达到我的要求,因为我几天后就被困住了.
更新:发现其中很少有用,但无法完成基于它们的要求:
以下是标记:
<asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
<asp:FileUpload ID="theFile" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Upload 1" onclick="Button2_Click" />
<asp:Button ID="Button1" runat="server" Text="Upload 1" onclick="btnUpload1_Click" />
<asp:Button ID="btnUpload" runat="server" Text="btnUpload_Click" onclick="btnUpload_Click" />
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:AjaxFileUpload ID="AjaxFileUpload2" runat="server" ToolTip="Upload File" ThrobberID="MyThrobber" onclientuploaderror="IsFileSizeGreaterThanMax" onuploadcomplete="AjaxFileUpload1_UploadComplete" AllowedFileTypes="jpg,jpeg,gif,png,pjpeg,zip,rar,pdf,xls,xlsx,doc,docx" MaximumNumberOfFiles="1" Height="50px" Width="350px"/>
<asp:Image id="MyThrobber" …Run Code Online (Sandbox Code Playgroud) 当我使用我正在处理的MVC应用程序上传大于4MB的文件到blob存储时,我遇到了一些问题.我在web.config中添加了必要的代码,如下所示:
在system.web中
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
Run Code Online (Sandbox Code Playgroud)
在system.webserver中
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)
我已经重建了我的web项目和我的azure项目,但我仍然得到超出最大请求长度的错误.可能导致这种情况的任何想法?堆栈跟踪如下:
[HttpException(0x80004005):超出了最大请求长度.] System.Web.HttpRequest.GetEntireRawContent()+ 12603644 System.Web.HttpRequest.GetMultipartContent()+221 System.Web.HttpRequest.FillInFormCollection()+357 System.Web.HttpRequest .EnsureForm()+110 System.Web.HttpRequest.get_Form()+ 16 System.IdentityModel.Services.WSFederationAuthenticationModule.IsSignInResponse(HttpRequestBase request)+32 System.IdentityModel.Services.WSFederationAuthenticationModule.CanReadSignInResponse(HttpRequestBase request,Boolean onPage)+129 System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender,EventArgs args)+152 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously )+165
file-upload web-config maxrequestlength blobstorage asp.net-mvc-4
我们正在构建一个Web API,它接收字符串数组作为输入参数,该参数查询oracle数据库并将结果作为JSON文件返回.
所以代码就像
namespace PDataController.Controllers
{
public class ProvantisDataController : ApiController
{
public HttpResponseMessage Getdetails([FromUri] string[] id)
{
List<OracleParameter> prms = new List<OracleParameter>();
string connStr = ConfigurationManager.ConnectionStrings["PDataConnection"].ConnectionString;
using (OracleConnection dbconn = new OracleConnection(connStr))
{
var inconditions = id.Distinct().ToArray();
var srtcon = string.Join(",", inconditions);
DataSet userDataset = new DataSet();
var strQuery = @"SELECT
STCD_PRIO_CATEGORY_DESCR.DESCR AS CATEGORY,
STCD_PRIO_CATEGORY_DESCR.SESSION_NUM AS SESSION_NUMBER,
Trunc(STCD_PRIO_CATEGORY_DESCR.START_DATE) AS SESSION_START_DATE,
STCD_PRIO_CATEGORY_DESCR.START_DATE AS SESSION_START_TIME ,
Trunc(STCD_PRIO_CATEGORY_DESCR.END_DATE) AS SESSION_END_DATE,
FROM
STCD_PRIO_CATEGORY_DESCR,
WHERE
STCD_PRIO_CATEGORY_DESCR.STD_REF IN(";
StringBuilder sb = new StringBuilder(strQuery);
for(int x …Run Code Online (Sandbox Code Playgroud) 该网页是一个简单的注册类型页面.每个用户必须填写大约200个字段.有1个父表和6个子表.每个表信息都显示在单独的AJAX选项卡面板中,详细信息将保存在每个选项卡导航中.我已经在Intranet中托管了该网站,并且同时由100个用户输入了详细信息.最初一切都进展顺利,条目被保存在数据库中,但有一段时间后,AJAX加载图像被显示,网站似乎非常慢.用户的详细信息未保存在数据库中.最后Firefox浏览器崩溃了一些人,有些应用程序甚至没有注销.该网站被绞死了!我也重置了IIS,一切都持续了几分钟,同样的问题又开始了!我使用NHibernate框架,AJAX,ASP.Net 4.0作为前端,SQL server 2008作为后端.
以下是日志文件中的错误详细信息:
2014-08-11 10:05:40,953 [22] INFO ASP.global_asax servername : -
************************* 11/08/2014 10:05 **************************** IP Address: xx.x.xxx.xx Exception Type: System.Web.HttpException Exception: Request timed out. Source:
**************************************************************************
2014-08-11 10:05:40,984 [39] INFO ASP.global_asax servername : -
************************* 11/08/2014 10:05 ****************************`
IP Address: xx.x.xxx.xx
Exception Type: System.Web.HttpException
Exception: The client disconnected.
Source: System.Web
Stack Trace:
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState)
at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded()
at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
at System.Web.UI.Control.ValidateEvent(String uniqueID, String …Run Code Online (Sandbox Code Playgroud) 我遇到最大请求长度超出错误的问题,当我尝试在我的.net mvc应用程序中上传超过3-4张照片时,我得到:
Server Error in '/' Application.
Run Code Online (Sandbox Code Playgroud)
我找到了IIS 7的解决方案:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我尝试将其添加到我的web.config中,但可能不适用于IIS 10,或者我做错了,因为我仍然是新手。
更具体地说,让我解释一下我遇到了什么。我试图将数据列表从视图提交到控制器。我能够成功提交一些数据,没有任何问题。但当数据超过 250 个项目的列表时,问题就会出现。当我单击提交按钮时,它会在调试时传递 NULL 值。我的代码没有错误,因为我已经向控制器提交了 100 个项目的列表,没有任何问题。我想我必须指定一些东西,以便它也会发送大量列表。在这里,我没有使用 ajax 或任何 javascript 代码来提交表单。我使用发布请求将其直接提交给控制器。
我在下面发布了一些代码片段以更准确地描述它。
看法
<form method="post" action="SubmitList">
<div class="row">
<div class="col-md-12" style="padding-top:1%">
<input type="submit" value="PASS" class="btn btn-primary" style="float:right;" />
<div class="box-body">
<table id="#example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@{
int i = 1;
}
@for (int j = 0; j < Model.Count(); j++)
{
<tr>
<td>@Html.Raw(i++)</td>
@Html.HiddenFor(item => item[j].Id, new { htmlAttributes = new { @class = "form-control" } })
<td>
@Html.DisplayFor(item => item[j].FullName)
</td>
</tr> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ajax帖子将图像发送到asp.net Web表单
function SubmitFunction() {
alert(imgData_Based64String);
imgData_Based64String = "test";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm1.aspx/SaveImage",
data: "{ 'Based64BinaryString' :'" + imgData_Based64String + "'}",
dataType: "json",
success: function (data) {
},
error: function (result) {
alert("Error");
}
});
}
[System.Web.Services.WebMethod]
public static void SaveImage(string Based64BinaryString)
{
string Value = Based64BinaryString;
}
Run Code Online (Sandbox Code Playgroud)
一切都好.
"test"消息到达服务器端的SaveImage函数.
但当我尝试发送实际的基于64string(删除"测试"虚拟消息后)
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10 ....
Run Code Online (Sandbox Code Playgroud)
它永远不会达到服务器端的SaveImage功能.它仅在浏览器开发者模式下显示以下错误.
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Run Code Online (Sandbox Code Playgroud) 我在尝试调试我的应用程序时遇到了seuinte错误.
HTTP错误404.13 - 未找到
请求过滤模块被配置为拒绝超过请求内容大小的请求.
检查configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in applicationhost.config或web.config文件.
我的web.config
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="31457280"/>
</requestFiltering>
</security> </system.webServer>
Run Code Online (Sandbox Code Playgroud)
更多信息:
这和安全功能.不要改变少于完全理解变化的范围.快速您可以配置IIS服务器以拒绝其内容大于指定的嗡嗡声值的请求.如果返回的请求内容大于set*Size ESSE错误.需要增加*内容大小,修改配置configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength .
asp.net ×8
c# ×7
asp.net-mvc ×3
ajax ×2
file-upload ×2
asp.net-4.0 ×1
asp.net-core ×1
blobstorage ×1
forms ×1
http-post ×1
iis ×1
iis-7 ×1
iis-7.5 ×1
jquery ×1
json ×1
oracle ×1
rest ×1
security ×1
servicestack ×1
web-config ×1