[英]500 Internal Server Error in production when submitting base64 image to jquery ajax and web method
Having a difficult time figuring this one out. 很难解决这个问题。 I'd really appreciate some help.
我真的很感谢您的帮助。
Works fine on localhost and single test server. 在localhost和单个测试服务器上工作正常。 Production environment is a web cluster.
生产环境是一个网络集群。
Removing the base64 image from data array in the ajax call and as a parameter in the web method allows everything to work fine. 从ajax调用中的数据数组中删除base64图像,并将其作为web方法中的参数,可以使一切正常运行。
Here's my code: 这是我的代码:
JS JS
var img = $('.finalize-img').attr('src'); //Src is a base64 string
//var img = base64.replace(/^data:image\/(png|jpg);base64,/, "");
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'Thank-You.aspx/Upload',
dataType: "json",
processData: false,
data: "{'img':'" + img + "', 'firstname':'" + firstname + "', 'lastname':'" + lastname + "', 'emailaddress':'" + emailaddress + "'}",
success: function (msg) {
var m = msg.d;
},
error: function (jqXHR, error, errorThrown) {
if (jqXHR.status && jqXHR.status == 400) {
alert('An error occurred. Please try again.');
//alert(jqXHR.status + " -- " + jqXHR.responseText);
}
}
});
C# C#
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Upload(string img, string firstname, string lastname, string emailaddress)
{
string base64 = img.Replace("data:image/png;base64,", "");
string path = ConfigurationManager.AppSettings["UploadImagePath"];
string fileName = "Image_" + DateTime.UtcNow.Year + DateTime.UtcNow.Month + DateTime.UtcNow.Day + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second + DateTime.UtcNow.Millisecond + "_" + Guid.NewGuid() + ".jpg";
int imageQuality;
if (!int.TryParse(ConfigurationManager.AppSettings["UploadImageQuality"], out imageQuality))
{
imageQuality = 50;
}
byte[] bytes = Convert.FromBase64String(img);
System.Drawing.Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = System.Drawing.Image.FromStream(ms);
}
try
{
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, imageQuality);
ImageCodecInfo jpegCodec = null;
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
for (int i = 0; i < codecs.Length; i++)
{
if (codecs[i].MimeType == "image/jpeg")
{
jpegCodec = codecs[i];
}
}
if (jpegCodec != null)
{
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
image.Save(path + fileName, jpegCodec, encoderParams);
}
}
catch (Exception ex)
{
return "Message:" + ex.Message + " Source:" + ex.Source + " Inner Exception:" + ex.InnerException;
}
return fileName;
}
*********UPDATE********** Found this in the event viewer Event code: 3005 Event message: An unhandled exception has occurred. *********更新**********在事件查看器中找到了此事件代码:3005事件消息:发生未处理的异常。 Event time: 10/18/2016 3:32:57 PM Event time (UTC): 10/18/2016 8:32:57 PM Event ID: 6a016eb99ac74d558cb1ec42df643299 Event sequence: 13221 Event occurrence: 12 Event detail code: 0
事件时间:10/18/2016 3:32:57 PM事件时间(UTC):10/18/2016 8:32:57 PM事件ID:6a016eb99ac74d558cb1ec42df643299事件序列:13221事件发生:12事件详细代码:0
Application information: Application domain: /LM/W3SVC/2/ROOT-5-131212864443437500 Trust level: Full Application Virtual Path: / Application Path: D:\\Websites\\MS\\ Machine name: MOVWEB4 应用程序信息:应用程序域:/ LM / W3SVC / 2 / ROOT-5-131212864443437500信任级别:完整应用程序虚拟路径:/应用程序路径:D:\\ Websites \\ MS \\机器名称:MOVWEB4
Process information: Process ID: 4048 Process name: w3wp.exe Account name: NT AUTHORITY\\NETWORK SERVICE 进程信息:进程ID:4048进程名称:w3wp.exe帐户名:NT AUTHORITY \\ NETWORK SERVICE
Exception information: Exception type: ArgumentException Exception message: Unknown web method Upload. 异常信息:异常类型:ArgumentException异常消息:未知的Web方法上载。 Parameter name: methodName at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
参数名称:System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()的System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender,EventArgs eventArgs)处的methodName(System.Web.HttpApplication.ExecuteStep() IExecutionStep步骤,布尔值和已同步完成)
Request information: Request URL: http://beta.ms.com/Thank-You.aspx/Upload Request path: /Thank-You.aspx/Upload User host address: 请求信息:请求URL: http ://beta.ms.com/Thank-You.aspx/Upload请求路径:/Thank-You.aspx/Upload用户主机地址:
User: Anonymous Is authenticated: False Authentication Type: 用户:匿名通过身份验证:错误身份验证类型:
Thread account name: NT AUTHORITY\\NETWORK SERVICE 线程帐户名称:NT AUTHORITY \\ NETWORK SERVICE
Thread information: Thread ID: 27 Thread account name: NT AUTHORITY\\NETWORK SERVICE Is impersonating: False Stack trace: at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 线程信息:线程ID:27线程帐户名称:NT AUTHORITY \\ NETWORK SERVICE正在模拟:False堆栈跟踪:位于System.Web.HttpApplication.SyncEventExecutionStep.System处的System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender,EventArgs eventArgs) System.Web.HttpApplication.ExecuteStep处的.Web.HttpApplication.IExecutionStep.Execute()(IExecutionStep步骤,布尔值和完成同步)
Custom event details: 自定义事件详细信息:
您必须将IIS用户组的写权限授予您尝试上载文件ConfigurationManager.AppSettings [“ UploadImagePath”]的文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.