【发布时间】:2016-02-11 09:39:45
【问题描述】:
当我想添加 addJsonFile 时,我会使用 NullReferenceException。我完全按照 lynda(http://www.lynda.com/ASP-NET-tutorials/Dynamically-control-behavior-custom-configuration/368051/431234-4.html) 的说法。
(screenShot)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNet.Diagnostics;
using Microsoft.Framework.Internal;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.ConfigurationModel.Json;
namespace PortalDemo
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
var config = new Configuration();
config.AddEnvironmentVariables();
config.AddJsonFile("config.json");//Here
if (config.Get("debug") == "True")
{
app.UseRuntimeInfoPage();
app.UseDeveloperExceptionPage();
}
app.UseExceptionHandler("/home/errorPage");
app.UseMvc(routes=>
routes.MapRoute("Default","{controller=Home}/{action=Index}/{id?}"));
app.UseStaticFiles();
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
}
【问题讨论】:
-
尝试使用 Rene 给您的链接研究您的异常。我找不到它,请在此处发布您的完整堆栈跟踪。完整的 StackTrace 对于查找错误至关重要。
标签: asp.net-core-mvc