您的位置:首页 > 科技 > IT业 > 免费个人网站服务器 html_盐城优化办_seo关键词排名查询_视频外链在线生成

免费个人网站服务器 html_盐城优化办_seo关键词排名查询_视频外链在线生成

2024/11/16 17:27:40 来源:https://blog.csdn.net/u011511086/article/details/143177377  浏览:    关键词:免费个人网站服务器 html_盐城优化办_seo关键词排名查询_视频外链在线生成
免费个人网站服务器 html_盐城优化办_seo关键词排名查询_视频外链在线生成

微软asp.net core帮助文档
asp.net core会话
https://learn.microsoft.com/zh-cn/aspnet/core/fundamentals/app-state?view=aspnetcore-8.0

Program.cs 文件中,核心代码:

builder.Services.AddSession(options => { //滑动过期时间,空闲多长时间没有操作会过期;options.IdleTimeout = TimeSpan.FromSeconds(30);
});

Program.cs 完整代码

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
using WebProjectNet7;
using WebProjectNet7.DataBaseEntity.Tool;
using WebProjectNet7.DependencyInjection;
using WebProjectNet7.Handler;
using WebProjectNet7.IBLL;
using WebProjectNet7.IBLL_impl;
using WebProjectNet7.IDAO;
using WebProjectNet7.IDAO_impl;
using WebProjectNet7.ViewEntity;var builder = WebApplication.CreateBuilder(args);//依赖注入,注册接口,修改时间:2024-2-19 13:45:17,
ServicesRegister.Register(builder);// Views视图文件输出到发布目录
//builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
builder.Services.AddRazorPages();builder.Services.AddControllersWithViews(ops =>
{//全局异常过滤器,注册ops.Filters.Add<ExceptionFilter>();
})// Views视图文件输出到发布目录.AddRazorRuntimeCompilation().AddNewtonsoftJson(options =>
{options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});builder.Services.AddSession(options => { //滑动过期时间,空闲多长时间没有操作会过期;options.IdleTimeout = TimeSpan.FromSeconds(30);
});builder.Services.AddHttpContextAccessor();
//解决输入页面中文被编码了
builder.Services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));// 添加 CORS 支持,允许跨域
builder.Services.AddCors(options =>
{options.AddPolicy("AllowAnyOrigin",builder =>{builder.AllowAnyOrigin()     // 允许任何来源.AllowAnyHeader()     // 允许任何头部.AllowAnyMethod();    // 允许任何 HTTP 方法});
});var app = builder.Build();if (!app.Environment.IsDevelopment())
{app.UseExceptionHandler("/Home/Error");
}
// 启用 CORS 中间件
app.UseCors("AllowAnyOrigin");app.UseStaticFiles();app.UseRouting();string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, MyConfigReader.GetConfigValue("uploadFilefolder"));
if (!System.IO.Directory.Exists(dir))
{System.IO.Directory.CreateDirectory(dir);
}string direxport = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, MyConfigReader.GetConfigValue("exportFilefolder"));
if (!System.IO.Directory.Exists(direxport))
{System.IO.Directory.CreateDirectory(direxport);
}
//配置静态文件,暴露在http管道中,以供浏览器访问
app.UseStaticFiles(new StaticFileOptions()
{RequestPath = new PathString("/" + MyConfigReader.GetConfigValue("uploadFilefolder")),FileProvider = new PhysicalFileProvider(dir)
});app.UseStaticFiles(new StaticFileOptions()
{RequestPath = new PathString("/" + MyConfigReader.GetConfigValue("exportFilefolder")),FileProvider = new PhysicalFileProvider(direxport)
});app.UseAuthorization();app.UseSession();app.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");AppServicesHelpter.App = app;app.Run();

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com