我有一个ASP.Net Web 2项目。在静态构造函数中的控制器中,初始化Infer.Net模型。当我在本地运行该项目时,要么选择web应用程序作为Visual 2013中的启动项目,要么选择Azure Cloud服务项目作为启动项目,它运行良好,静态构造函数运行,而web API调用返回预期值。
但是,当我将站点部署到Azure并尝试调用任何web控制器的方法时,它们都会失败,我得到了异常System.InvalidOperationException并给出了解释
An error occurred when trying to create a controller of type 'TwentyQuestionsController'.
Make sure that the controller has a parameterless public constructor.(确实如此)
查看内部异常的细节,下一个异常是System.TypeInitializationException
The type initializer for 'GuessingGamesWebApplication.Controllers.TwentyQuestionsController'
threw an exception在堆栈跟踪下面,我看到了一个System.UnauthorizedAccessException
Access to the path d:\windows\system32\inetsrv\GeneratedSource' is denied看起来,当我在本地运行项目时,web角色进程有足够的权限让Infer.Net构建和编译形成模型的本地文件,但是在Azure中,web角色进程缺乏这些特权。
如何将ASP.Net WebAPI2web角色部署到Azure,并赋予Infer.Net足够的权限来构建和编译构成模型的本地文件?
(注:我使用Infer.Net 2.6.41114.1通过NuGet。)
==========编辑===========
看看this answer的问题Can I write to file system on azure web site?,web角色写权限仅限于我的应用程序的根文件夹。因此,另一种解决方案是将Infer.Net配置为在那里而不是在d:\windows\system32\inetsrv\中编写。我如何配置Infer.Net来做到这一点?
发布于 2015-01-09 09:51:17
明白了。我将源文件夹路径添加到我的Infer.Net模型类的构造函数中:
public LiveDatabaseGamesEngines(string generatedSourceFolder = "MyGeneratedSourceFolder")
{
InferenceEngine.DefaultEngine.Compiler.GeneratedSourceFolder = generatedSourceFolder;
// rest of code...
}然后,在我的ASP.Net Web 2控制器中的静态构造函数中,我可以传递应用程序路径:
var generatedSourceFolderPath = HostingEnvironment.MapPath("~/MyGeneratedSourceFolder");
_GamesEngines = new LiveDatabaseGamesEngines(generatedSourceFolderPath);https://stackoverflow.com/questions/27856599
复制相似问题