Koo*_*ler 5 c# asp.net-mvc azure azure-web-sites asp.net-core-mvc
我创建了一个ASP.NET MVC Core项目并注册了一些自定义文件夹来搜索Views.我用这样的自定义IViewLocationExpander类做了这个:
public class AppsViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
{
yield return "/MyViewLocation/A/Views";
//and so on...
}
Run Code Online (Sandbox Code Playgroud)
并在Startup.cs中使用此类:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new AppsViewLocationExpander());
});
}
Run Code Online (Sandbox Code Playgroud)
在MyViewLocation/A/Views文件夹中有一些*.cshtml文件,本地调试会话继续进行,没有任何错误.现在我将Web应用程序发布到Azure,我收到了500内部服务器错误.我附加Visual Studio来调试此错误并收到此消息:
System.InvalidOperationException:找不到视图"索引".搜索了以下位置:/
MyViewLocation/A/Views/Index.cshtml
我错了什么?我是否还必须在其他地方添加Views-Folder?
编辑:
我在初始设置时修改了我的project.json,但这对我的Azure问题没有帮助.但可能有必要在我本地调试期间找到视图.
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"MyViewLocation/**/Views",
"appsettings.json",
"web.config"
]
},
Run Code Online (Sandbox Code Playgroud)
编辑2:
我手动将*.cshtml文件上传到FTP服务器.然而,他们仍然没有找到.
我在 .NET Core 2.2 中遇到了同样的问题,它是*.csproj中的设置。不知何故,我不小心将视图排除在发布之外。
<ItemGroup>
<Content Remove="Views\ToDos\Edit.cshtml" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
当我从项目设置中删除上面的行后,视图就被发布了。
| 归档时间: |
|
| 查看次数: |
1692 次 |
| 最近记录: |