.netcore razor设置启动页,默认页,以及获取配置文件appsettings.json数据
[C#] 纯文本查看 复制代码 // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddRazorPagesOptions(options =>
{
options.RootDirectory = "/Pages";//默认目录
//options.Conventions.AddPageRoute("/pages", "/1");//重写URL
//options.Conventions.AddPageRoute("/sufei", "");//默认主页
});
//获取配置数据
string con1= Configuration["con1"];
string con2 = Configuration["con2"];
string con3 = Configuration["con3"];
}
|