排名
1
文章
860
粉丝
112
评论
163
.net core自定义项目模板,创建自己的模板项目,使用命令行创建模板项目
尘叶心繁 : 可以可以讲真的我都想弄个模板
net core webapi post传递参数
庸人 :
确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
.net webapi 返回需要的字段,忽略某些字段,修改字段名等
雨雨雨雨雨辰 : 已精
.net webapi 返回需要的字段,忽略某些字段,修改字段名等
雨雨雨雨雨辰 :
疯狂反射
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

.net core中可以使用中间件处理路由,如下在Configure直接使用:
- //自定义中间件来实现一个路由
- app.Use(next => async context =>
- {
- if (context.Request.Path == "/")
- {
- await context.Response.WriteAsync("Hello terminal middleware!");
- return;
- }
- if (context.Request.Path == "/home/about")
- {
- context.Response.ContentType = "text/html;charset=UTF-8";
- await context.Response.WriteAsync("关于我们页面!");
- return;
- }
- if (context.Request.Path == "/home/about.html")
- {
- //context.Response.Redirect("/home/Privacy");
- context.Response.ContentType = "text/html;charset=UTF-8";
- await context.Response.WriteAsync("伪静态!");
- return;
- }
- await next(context);
- });
中间件也可以封装到文件中去使用:
- namespace MyFirstNETCORE.Middleware
- {
- public class UrlMiddleware
- {
- private readonly RequestDelegate _next;
- private readonly ILogger _logger;
- public UrlMiddleware(RequestDelegate next, ILoggerFactory logger)
- {
- _next = next;
- _logger = logger.CreateLogger<RequestIPMyMiddleware>();
- }
- public async Task Invoke(HttpContext context)
- {
- //if (context.Request.Path == "/")
- //{
- // await context.Response.WriteAsync("Hello terminal middleware!");
- // return;
- //}
- if (context.Request.Path == "/home/about")
- {
- context.Response.ContentType = "text/html;charset=UTF-8";
- await context.Response.WriteAsync("关于我们页面!");
- return;
- }
- if (context.Request.Path == "/home/about.html")
- {
- //context.Response.Redirect("/home/Privacy");
- context.Response.ContentType = "text/html;charset=UTF-8";
- await context.Response.WriteAsync("伪静态!");
- return;
- }
-
- await _next.Invoke(context); //执行下一个中间件
- }
- }
-
- public static class UrlMiddlewareExtensions
- {
- public static IApplicationBuilder UseMyUrl(this IApplicationBuilder app)
- {
- app.UseMiddleware<UrlMiddleware>();
- return app;
- }
- }
- }
然后像其他中间件一样使用即可:
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)
评价