1
當我嘗試啓動我的項目時,我的Home端點不起作用。 我可以看到它在斷點處擊中HomeController並返回失敗的視圖。
我其他的API端點的作品如: /API /價值/Aspnet Core Razor視圖編譯失敗
我試圖運行本地在這一點上,但計劃是部署到AWS LAMBDA。
我有3個控制器:
- 的HomeController
- S3ProxyController
- ValuesController
但是,當我試圖訪問我的主頁控制器,它應該回到一個簡單的觀點,我得到以下錯誤:
我已經加入我的csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<OutputTypeEx>exe</OutputTypeEx>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.0" />
<PackageReference Include="AWSSDK.S3" Version="3.3.5.13" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.0.3" />
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.1.0" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="0.10.1-preview1" />
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="1.5.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project>
下面在這裏我已經添加了啓動文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace TestLambda
{
public class Startup
{
public const string AppS3BucketKey = "AppS3Bucket";
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public static IConfigurationRoot Configuration { get; private set; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddAWSService<Amazon.S3.IAmazonS3>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddLambdaLogger(Configuration.GetLambdaLoggerOptions());
app.UseMvc();
app.UseDeveloperExceptionPage();
app.UseMvcWithDefaultRoute();
}
}
}
下面這裏是項目結構:
添加代碼到家庭控制器:
using System;
using Microsoft.AspNetCore.Mvc;
namespace TestLambda.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View(); // Breakpoint get's hit during debuging.
}
public IActionResult Error()
{
return View();
}
}
}
另一個帶有視圖的控制器是否有效?嘗試用基本視圖創建新的控制器(不是api)。請提供家庭控制器代碼,並嘗試更新.Net Core包 – itikhomi
新增HomeController。它或多或少都很簡單:) – Kiksen
增加了AccountController,它收到相同的錯誤信息。 – Kiksen