Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.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
Asp.net 为什么R.NET在本地工作,但在IIS中停止工作?_Asp.net_R_Ajax_Rstudio_R.net - Fatal编程技术网

Asp.net 为什么R.NET在本地工作,但在IIS中停止工作?

Asp.net 为什么R.NET在本地工作,但在IIS中停止工作?,asp.net,r,ajax,rstudio,r.net,Asp.net,R,Ajax,Rstudio,R.net,我有一个ASP.NET MVC应用程序,它向R脚本发送参数,然后R脚本生成一个文件并将其放在本地文件夹中。这个过程通过VisualStudio在我的本地机器上运行得很好,但是在我发布和使用IIS之后,它会进入和退出。下面是我如何初始化R.NET并通过AJAX从视图中获取这些值 我还将这两个路径放置在我的系统环境变量中 如果有人知道为什么IIS只能在我重启操作系统后立即工作,然后在我重启操作系统后不久停止工作,我将不胜感激。奇怪的是,我在visualstudio中没有遇到IIS中遇到的问题

我有一个ASP.NET MVC应用程序,它向R脚本发送参数,然后R脚本生成一个文件并将其放在本地文件夹中。这个过程通过VisualStudio在我的本地机器上运行得很好,但是在我发布和使用IIS之后,它会进入和退出。下面是我如何初始化R.NET并通过AJAX从视图中获取这些值

我还将这两个路径放置在我的系统环境变量中

如果有人知道为什么IIS只能在我重启操作系统后立即工作,然后在我重启操作系统后不久停止工作,我将不胜感激。奇怪的是,我在visualstudio中没有遇到IIS中遇到的问题

        [HttpGet]
    public JsonResult Index1(string modelTypes = null, string fileNames = null, string[] locations = null, string lowerLimits = null, string upperLimits = null, string areas = null, string productivities = null, string[] fobs = null)
    {
        @ViewBag.UserName = System.Environment.UserName;
        string userName = @ViewBag.UserName;
        //Declare field parameters
        var strModelTypeValue = modelTypes;
        string strFileName = fileNames;
        var strLocationValue = locations;
        var strLowerLimitValue = lowerLimits;
        var strUpperLimitValue = upperLimits;
        string strAreaValue = areas;
        string strProductivityValue = productivities;
        string strFobValue = fobs.ToString();
        var libraryLocation = "C:/Users/" + userName + "/Documents/R/win-library/3.2";

        string rPath = @"C:\Program Files\R\R-3.3.2\bin\x64";
        string rHome = @"C:\Program Files\R\R-3.3.2";

        //Initialize REngine
        REngine.SetEnvironmentVariables(rPath, rHome);
        REngine engine = REngine.GetInstance();
        engine.Initialize();

        if (fobs.Length > 1)
        {
            strFobValue = string.Join(" ", fobs);
        }
        else
        {
            strFobValue = "ALL";
        }




        //Declare R Script path
        var rScriptPath = "C:/Users/" + userName + "/Documents/R/RWDir/Loop_Optimization.R";

        //Check to see if there was more than one location selected
        if (strLocationValue.Length > 1)
        {

            foreach (var item in strLocationValue)
            {
                //Set string location to each location value in loop
                var strlocation = item;

                //Add values to parameter list
                var myParams = new List<string>
                {       

                    strModelTypeValue,
                    strFileName,               
                    strlocation,                
                    strLowerLimitValue,
                    strUpperLimitValue,
                    strAreaValue,
                    strProductivityValue,
                    strFobValue,
                    libraryLocation

                };

                //Set myParams as arguments to be sent to r script
                engine.SetCommandLineArguments(myParams.ToArray());
                engine.Evaluate("source('" + rScriptPath + "')");
            }

        }
        //Only one location specified, no need to loop
        else
        {
            foreach (var item in strLocationValue)
            {
                //Set string location to each location value in loop
                var strlocation = item;
                var myParams = new List<string>
                {

                    strModelTypeValue,
                    strFileName,
                    strlocation,
                    strLowerLimitValue,
                    strUpperLimitValue,
                    strAreaValue,
                    strProductivityValue,
                    strFobValue,
                    libraryLocation
                };

                engine.SetCommandLineArguments(myParams.ToArray());
                engine.Evaluate("source('" + rScriptPath + "')");
            }
        }
        //engine.Evaluate("source('" + rScriptPath + "')");
        //engine.Dispose();
        return Json("success", JsonRequestBehavior.AllowGet);

    }
[HttpGet]
public JsonResult Index1(字符串modelTypes=null,字符串filename=null,字符串[]位置=null,字符串lowerLimits=null,字符串上限=null,字符串区域=null,字符串生产力=null,字符串[]fobs=null)
{
@ViewBag.UserName=System.Environment.UserName;
字符串userName=@ViewBag.userName;
//声明字段参数
var strModelTypeValue=模型类型;
字符串strFileName=文件名;
var strLocationValue=位置;
var strLowerLimitValue=lowerLimits;
var strUpperLimitValue=上限;
字符串值=面积;
字符串strProductivityValue=生产力;
字符串strFobValue=fobs.ToString();
var libraryLocation=“C:/Users/“+userName+”/Documents/R/win library/3.2”;
字符串rPath=@“C:\ProgramFiles\R\R-3.3.2\bin\x64”;
字符串rHome=@“C:\ProgramFiles\R\R-3.3.2”;
//初始化引擎
设置环境变量(rPath,rHome);
REngine engine=REngine.GetInstance();
engine.Initialize();
如果(离岸价长度>1)
{
strFobValue=string.Join(“,fobs);
}
其他的
{
strFobValue=“全部”;
}
//声明R脚本路径
var rscript path=“C:/Users/“+userName+”/Documents/R/RWDir/Loop_Optimization.R”;
//检查是否选择了多个位置
如果(strLocationValue.Length>1)
{
foreach(strLocationValue中的var项)
{
//将字符串位置设置为循环中的每个位置值
var strlocation=项目;
//将值添加到参数列表
var myParams=新列表
{       
strModelTypeValue,
strFileName,
strlocation,
strLowerLimitValue,
strUpperLimitValue,
strAreaValue,
strProductivityValue,
strFobValue,
图书馆定位
};
//将myParams设置为要发送到r脚本的参数
engine.SetCommandLineArguments(myParams.ToArray());
Evaluate(“source(““+rscript路径+”)”);
}
}
//仅指定一个位置,无需循环
其他的
{
foreach(strLocationValue中的var项)
{
//将字符串位置设置为循环中的每个位置值
var strlocation=项目;
var myParams=新列表
{
strModelTypeValue,
strFileName,
strlocation,
strLowerLimitValue,
strUpperLimitValue,
strAreaValue,
strProductivityValue,
strFobValue,
图书馆定位
};
engine.SetCommandLineArguments(myParams.ToArray());
Evaluate(“source(““+rscript路径+”)”);
}
}
//Evaluate(“source(““+rscript路径+”)”);
//引擎。Dispose();
返回Json(“success”,JsonRequestBehavior.AllowGet);
}

您是否通过附加进程进行了任何调试。

我的web应用程序有时在IIS上工作,但只有在操作系统重新启动后,才会再次停止。我认为engine.Initialize();这导致了问题。是否有替代engine.Initialize()的方法来处理IIS?我现在正在将其重新创建为桌面应用程序,因为我在IIS上遇到了很多麻烦