Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Ajax Post在IIS托管网站中给出内部服务器错误500_.net_Ajax_Post_Iis 8_Asp.net Mvc 5 - Fatal编程技术网

.net Ajax Post在IIS托管网站中给出内部服务器错误500

.net Ajax Post在IIS托管网站中给出内部服务器错误500,.net,ajax,post,iis-8,asp.net-mvc-5,.net,Ajax,Post,Iis 8,Asp.net Mvc 5,异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例 这里返回部分视图并在ajax调用的success函数中重新加载视图。ReadText()方法在本地运行时工作正常,在IIS托管的网站上进行ajax调用时会出现内部服务器错误 我从Chrome的开发模式中获得的异常堆栈跟踪 [HttpPost] public ActionResult ReadText(HttpPostedFileBase file, string selected)

异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例

这里返回部分视图并在ajax调用的success函数中重新加载视图。ReadText()方法在本地运行时工作正常,在IIS托管的网站上进行ajax调用时会出现内部服务器错误 我从Chrome的开发模式中获得的异常堆栈跟踪

   [HttpPost]
    public ActionResult ReadText(HttpPostedFileBase file, string selected)
       {
     if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    Session["filename"] = fileName.Replace(".txt","");
                    string content = file.InputStream.ToString();
                    path = Path.Combine(Server.MapPath("~/UploadedImages/"), fileName);
                    file.SaveAs(path);
                    }
                string texts = System.IO.File.ReadAllText(path);
                texts = texts.Replace(","," ");
                    string ofile = "names.txt";
                    string Spellpath= Path.Combine(Server.MapPath("~/MegTrans/"), ofile);
                    TextWriter tw1 = new StreamWriter(Spellpath, false, Encoding.Default);


                    tw1.WriteLine(texts);

                    tw1.Close();
Session["score"] = texts;
            return PartialView("Results");
       }
[NullReferenceException:对象引用未设置为对象的实例。]
Tesseract_MVC_Test.Controllers.HomeController.ReadText(HttpPostedFileBase文件,选定字符串)+1675
lambda_方法(闭包、控制器基、对象[])+190
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)+228
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)+34
System.Web.Mvc.Async.AsyncControllerActionInvoker.b_u39(IAsyncResult asyncResult,ActionInvoking innerInvokeState)+38
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)+70
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+68
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+71
System.Web.Mvc.Async.c__显示类46.b_3f()+386
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+69
System.Web.Mvc.Async.c__显示类2b.b__1c()+38
System.Web.Mvc.Async.c__显示类21.b__1e(IAsyncResult asyncResult)+186
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+59
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+67
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+38
System.Web.Mvc.MvcHandler.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)+44
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+67
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+399
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+157

它是否真正进入控制器的代码中?控制器函数ReadText实际上是空的服务器端还是您只是没有发布代码。这将有助于了解哪一行代码失败。当我在本地运行它时,它工作正常,在将它发布到iis后,我发现使用firebugReadText的错误不是空的,它在ajax调用中停止,没有击中控制器,通过传递的变量的null引用获取内部服务器500可能是错误的,但是System.NullReferenceException是一个.net异常,它似乎表明ajax调用正在对服务器进行调用,但server.net代码中的某些内容导致了异常。它在本地运行时工作正常,iis是否阻止托管网站上的ajax调用?
   [HttpPost]
    public ActionResult ReadText(HttpPostedFileBase file, string selected)
       {
     if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    Session["filename"] = fileName.Replace(".txt","");
                    string content = file.InputStream.ToString();
                    path = Path.Combine(Server.MapPath("~/UploadedImages/"), fileName);
                    file.SaveAs(path);
                    }
                string texts = System.IO.File.ReadAllText(path);
                texts = texts.Replace(","," ");
                    string ofile = "names.txt";
                    string Spellpath= Path.Combine(Server.MapPath("~/MegTrans/"), ofile);
                    TextWriter tw1 = new StreamWriter(Spellpath, false, Encoding.Default);


                    tw1.WriteLine(texts);

                    tw1.Close();
Session["score"] = texts;
            return PartialView("Results");
       }
[NullReferenceException: Object reference not set to an instance of an object.]
   Tesseract_MVC_Test.Controllers.HomeController.ReadText(HttpPostedFileBase file, String selected) +1675
   lambda_method(Closure , ControllerBase , Object[] ) +190
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +228
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +34
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +38
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +68
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +71
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +69
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +59
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157