ASP.NET 5 RC 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)
转自:http://habrahabr.ru/company/microsoft/blog/268037/?mobile=no
1、project.json
{"version": "1.0.0-*","compilationOptions": {"emitEntryPoint": true},"dependencies": {"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final","Microsoft.AspNet.Routing": "1.0.0-rc1-final","Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final","Microsoft.Extensions.Configuration": "1.0.0-rc1-final"},"commands": {"web": "Microsoft.AspNet.Server.Kestrel"},"frameworks": {"dnx451": { },"dnxcore50": { }},"exclude": ["wwwroot","node_modules"],"publishExclude": ["**.user","**.vspscc"] }
2、appsettings.json
{"Data": {"DefaultConnection": {"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;"}} }
3、Startup.cs
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.Extensions.DependencyInjection; using AspNetCoreUrlRoutingDemo.PageRoute; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Configuration;namespace AspNetCoreUrlRoutingDemo {/// <summary>/// http://www.admin10000.com/document/7071.html/// </summary>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=398940public void ConfigureServices(IServiceCollection services){services.AddRouting();}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.public void Configure(IApplicationBuilder app){app.UseIISPlatformHandler();IConfigurationBuilder builder = new ConfigurationBuilder();builder.AddJsonFile("appsettings.json");IConfigurationRoot root = builder.Build();RouteBuilder routeBuilder = new RouteBuilder();routeBuilder.ServiceProvider = app.ApplicationServices;//indexrouteBuilder.DefaultHandler = new IndexPageRouteHandler(root, "index");routeBuilder.MapRoute("index_culture_", "{culture}/", new RouteValueDictionary { { "culture", "en" } }, new RouteValueDictionary { { "culture", @"\w{2}" } });app.UseRouter(routeBuilder.Build());//categoryrouteBuilder.DefaultHandler = new CategoryPageRouteHandler(root, "category");routeBuilder.MapRoute("category_", "{culture}/fashion/{leimu}/{pageindex}/", new RouteValueDictionary { { "pageindex", "1" }, { "culture", "en" } }, new RouteValueDictionary { { "leimu", "([\\w|-]+)(\\d+)" }, { "pageindex", "\\d+" }, { "culture", @"\w{2}" } });app.UseRouter(routeBuilder.Build());}// Entry point for the application.public static void Main(string[] args) => WebApplication.Run<Startup>(args);} }
4、IndexPageRouteHandler.cs
using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Configuration; using System.Diagnostics;namespace AspNetCoreUrlRoutingDemo.PageRoute {public class IndexPageRouteHandler : Microsoft.AspNet.Routing.IRouter{private string _name = null;private readonly IConfigurationRoot _configurationRoot;public IndexPageRouteHandler(IConfigurationRoot configurationRoot, string name){this._configurationRoot = configurationRoot;this._name = name;}public VirtualPathData GetVirtualPath(VirtualPathContext context){throw new NotImplementedException();}public async Task RouteAsync(RouteContext context){if (this._configurationRoot != null){string connectionString = this._configurationRoot.Get<string>("Data:DefaultConnection:ConnectionString");Debug.WriteLine(connectionString);}var routeValues = string.Join("", context.RouteData.Values);var message = String.Format("{0} Values={1} ", this._name, routeValues);await context.HttpContext.Response.WriteAsync(message);context.IsHandled = true;}} }
5、CategoryPageRouteHandler.cs
using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing; using Microsoft.Extensions.Configuration; using System.Diagnostics;namespace AspNetCoreUrlRoutingDemo.PageRoute {public class CategoryPageRouteHandler : Microsoft.AspNet.Routing.IRouter{private string _name = null;private readonly IConfigurationRoot _configurationRoot;public CategoryPageRouteHandler(IConfigurationRoot configurationRoot, string name){this._configurationRoot = configurationRoot;this._name = name;}public VirtualPathData GetVirtualPath(VirtualPathContext context){throw new NotImplementedException();}public async Task RouteAsync(RouteContext context){if (this._configurationRoot != null){string connectionString = this._configurationRoot.Get<string>("Data:DefaultConnection:ConnectionString");Debug.WriteLine(connectionString);}var routeValues = string.Join("", context.RouteData.Values);var message = String.Format("{0} Values={1} ", this._name, routeValues);await context.HttpContext.Response.WriteAsync(message);context.IsHandled = true;}} }
6、F5启动调试,
浏览器输入网址:http://localhost:16924/
浏览器输入网址:http://localhost:16924/en/fashion/wwww-1111/2
6、VS2015项目结构
ASP.NET 5 RC 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)相关推荐
- MacBookPro的系统偏好设置(包含触控板设置)
系统偏好设置 触控板: 光标与点按,打开"轻点来点按"(设置后就不用每次点击必须按下去) 更多手势,将"app切换轻扫"和"调度中心"改为四 ...
- ASP.NET WebHooks RC 1发布
正如消息队列能够让同一个组织内的多个应用相互通信一样, WebHooks也为来自不同组织的网站提供了一种以异步的形式进行通信的方法. \u0026#xD;\n\u0026#xD;\n 从本质上说,We ...
- php 设置window计划任务,windows下设置计划任务自动执行PHP脚本
背景: 环境部署在linux下或者windows中,可以使用windows的自动任务设置自动执行脚本执行一些日常运维任务 图形界面设置相对比较简单 准备工作: wamp(集成的PHP执行环境) 已经写 ...
- 设置中文linux输入ubuntu,Linux_ubuntu怎么设置成中文?ubuntu中文设置图文方法, 很多朋友安装ubuntu后,发 - phpStudy...
ubuntu怎么设置成中文?ubuntu中文设置图文方法 很多朋友安装ubuntu后,发现都是英文,看不懂要怎么办?其实ubuntu是可以设置成中文的,下文小编就为大家带来ubuntu中文的设置方法, ...
- IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android apk下载的MIME 设置 苹果ISO .ipa下载mime 设置...
IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android apk下载的MIME 设置 苹果ISO .ipa下载mime 设置 原文:IIS 添加mime 支持 a ...
- linux设置开机自启服务,linux设置服务开机自启动的三种方式
linux设置服务开机自启动的三种方式 这里介绍一下linux开机自动启动的几种方法,共计3种,大家可以借鉴一下!经验里面以centos 5.3系统为例! 方法1:.利用ntsysv命令进行设置,利用 ...
- 小米4c怎么添加语言怎么设置在哪里,小米4c路由器设置教程
摘要 腾兴网为您分享:番茄小说,唱吧app,酷狗,腾讯会议,唯品会等知识经验教程,欢迎大家关注腾兴网. 小米4c路由器该怎么设置,不少小伙伴们不清楚设置方法是什么,想要知道该怎么设置的,就让小编给大家 ...
- R语言ggplot2可视化设置数据点的大小、设置数据点的颜色、设置数据点边缘线条的厚度(point border thickness)实战
R语言ggplot2可视化设置数据点的大小.设置数据点的颜色.设置数据点边缘线条的厚度(point border thickness)实战 目录
- TextView设置文字包含中英文时自动换行问题的终极解决方案
TextView设置文字包含中英文时自动换行问题的终极解决方案 参考文章: (1)TextView设置文字包含中英文时自动换行问题的终极解决方案 (2)https://www.cnblogs.com/ ...
最新文章
- tensorflow中的log中数字的含义
- SAP 电商云 Spartacus UI added-to-cart 的端到端测试源代码解析
- P3733 [HAOI2017]八纵八横(线性基/线段树分治)
- 7种常用p2p共享协议
- 线程锁定CPU linux,linux 线程与CPU绑定
- scilab和matlab的区别,matlab 与scilab的比较.doc
- SEO思维的优化源于生活
- xtrabackup 2.4.3 BUG
- BatchPreparedStatementSetter,用法
- DIV_ROUND_CLOSEST函数
- Win10人脉应用将关闭与新浪微博关联
- 使用FlyMcu ISP清除 STM32F411CE 芯片卡死
- FastStone Capture 9.3 汉化绿色便携版 - 极品屏幕截图工具
- Android App 安全登录认证解决方案
- 蓝桥杯--并查集1 sdutoj 小雷的冰茶几
- HLS第十二课(bayer photo)
- 使用google.zxing制作条形码和二维码
- MEC@JavaSE@实战篇@笔记05@计算机网络技术基础
- 人工智能(8)---一文读懂人工智能产业链:基础技术、人工智能技术及人工智能应用
- 1、RL Problem