ASP.NET 5 RC 2:UrlRouting 设置(不包含MVC6的UrlRouting设置)
0、Program.cs
using System.IO;
using Microsoft.AspNetCore.Hosting; namespace AspNetCoreUrlRoutingDemoRC2
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build(); host.Run();
}
}
}
1、project.json
{
"userSecretsId": "aspnet-WebApplicationCore1-782de49b-8e7f-46be-82aa-0f48e1d370bc",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Routing": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Routing.Abstractions": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final"
}, "tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
}, "frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
}, "buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
}, "runtimeOptions": {
"gcServer": true
}, "publishOptions": {
"include": [
"wwwroot",
"web.config"
]
}, "scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
2、appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplicationCore1-782de49b-8e7f-46be-82aa-0f48e1d370bc;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
3、Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using AspNetCoreUrlRoutingDemoRC2.PageRoute; namespace AspNetCoreUrlRoutingDemoRC2
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
IConfigurationBuilder builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();//project.json -> userSecretsId
} builder.AddEnvironmentVariables();
this.Configuration = builder.Build();
} public IConfigurationRoot Configuration { get; } // 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.AddRouting();
} public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(); if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/error");
} app.UseStaticFiles();
//app.UseIdentity(); RouteBuilder routeBuilder = new RouteBuilder(app); //index
routeBuilder.DefaultHandler = new IndexPageRouteHandler(this.Configuration, "index");
routeBuilder.MapRoute("index_culture_", "{culture}/", new RouteValueDictionary { { "culture", "en" } }, new RouteValueDictionary { { "culture", @"\w{2}" } });
app.UseRouter(routeBuilder.Build()); //category
routeBuilder.DefaultHandler = new CategoryPageRouteHandler(this.Configuration, "category");
routeBuilder.MapRoute("category_", "{culture}/fashion/{leimu}/{pageindex}/", new RouteValueDictionary { { "pageindex", "" }, { "culture", "en" } }, new RouteValueDictionary { { "leimu", "([\\w|-]+)(\\d+)" }, { "pageindex", "\\d+" }, { "culture", @"\w{2}" } }); app.UseRouter(routeBuilder.Build()); }
}
}
4、IndexPageRouteHandler.cs
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Http;
using System.Diagnostics; namespace AspNetCoreUrlRoutingDemoRC2.PageRoute
{
public class IndexPageRouteHandler : IRouter
{
private string _name = null;
private readonly IConfigurationRoot _configurationRoot; public IndexPageRouteHandler(IConfigurationRoot configurationRoot, string name)
{
this._configurationRoot = configurationRoot;
this._name = name;
} public async Task RouteAsync(RouteContext context)
{
if (this._configurationRoot != null)
{
string connectionString = this._configurationRoot.GetConnectionString("DefaultConnection");
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);
} public VirtualPathData GetVirtualPath(VirtualPathContext context)
{
throw new NotImplementedException();
}
}
}
5、CategoryPageRouteHandler.cs
using Microsoft.AspNetCore.Routing;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using System.Diagnostics; namespace AspNetCoreUrlRoutingDemoRC2.PageRoute
{
public class CategoryPageRouteHandler : IRouter
{
private string _name = null;
private readonly IConfigurationRoot _configurationRoot; public CategoryPageRouteHandler(IConfigurationRoot configurationRoot, string name)
{
this._configurationRoot = configurationRoot;
this._name = name;
} public async Task RouteAsync(RouteContext context)
{
if (this._configurationRoot != null)
{
string connectionString = this._configurationRoot.GetConnectionString("DefaultConnection");
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);
} public VirtualPathData GetVirtualPath(VirtualPathContext context)
{
throw new NotImplementedException();
}
}
}
6、F5启动调试,
浏览器输入网址:http://localhost:16924/
浏览器输入网址:http://localhost:16924/en/fashion/wwww-1111/2
6、VS2015项目结构
ASP.NET 5 RC 2:UrlRouting 设置(不包含MVC6的UrlRouting设置)的更多相关文章
- ASP.NET 5 RC 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)
转自:http://habrahabr.ru/company/microsoft/blog/268037/?mobile=no 1.project.json { "version" ...
- ASP.NET Core 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)
0.Program.cs using System.IO; using Microsoft.AspNetCore.Hosting; namespace WebApplication1 { public ...
- Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置
解决思路: 1.找个可用的Aspose.Cells(有钱还是买个正版吧,谁开发个东西也不容易): 2.在.Net方案中引用此Cells: 3.写个函数ToExcel(传递一个DataTable),可以 ...
- 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 设置 站点--右键属性--http头 ...
- Web.config中的设置 forms 中的slidingExpiration的设置
在ASP.NET 网站中,使用 Forms Authentication时,一般的设置是如下的: <authentication mode="Forms"> <f ...
- 无线路由器的设置_不能通过wifi进行设置
昨天朋友的小区宽带续费完不能上网了,过去看了一下,无线路由器没有问题,但是宽带信号没过来,网线直接插在电脑上用拨号,发现根本没办法连接,提示网线已经被拔出,重新还原一下系统,也是不行.因为之前他的电脑 ...
- 实现ScrollView中包含ListView,动态设置ListView的高度
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- iOS “请在微信客户端打开链接” UIWebview加载H5页面携带session、cookie、User-Agent信息 设置cookie、清除cookie、设置User-Agent
公司新开的一个项目..内容基本上是加载H5页面显示..当时觉得挺简单的..后来发现自己掉坑里了..一些心理历程就不说了..说这个项目主要用到的知识点吧..也是自己踩得坑. 首先说说..这个项目上的内容 ...
- 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选
设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...
随机推荐
- HTTPS 原理与证书实践
1.1 网络安全知识 1.1.1 网结安全出现背景 网络就是实现不同主机之间的通讯,网络出现之初利用TCP/IP协议簇的相关协议概念,已经满足了互连两台主机之间可以进行通汛的目的,虽然看似简简单单几句 ...
- linux安装experss搭建本地服务器
准备nodejs和npm 保证本地安装了nodeJS和npm,如果没有安装的话,通过下面的命令进行安装: sudo apt-get install nodejs //安装nodeJS sudo apt ...
- ArcGIS鼠标滚轮方向之注册表篇
ArcMap鼠标滚轮方向的设置是记录在注册表信息中,那么我们做一个简单的测试.先打开注册表,将ReverseMouseWheel删除,再打开ArcMap进行鼠标滚轮方向设置. 设置完成后,刷新注册表, ...
- Python过滤emoji
参考博客:http://my.oschina.net/jiemachina/blog/189460 1. 将emoji表情替换为指定字符串 import re def filter_emoji(des ...
- AfterAddJS
protected override string AfterAddJS() { return CanDoo.FineUI.Utility.AfterSaveJS_ReloadData(EntityI ...
- JAVA设计模式——第 7 章 门面模式【Facade Pattern】(转)
好,我们继续讲课.大家都是高智商的人,都写过纸质的信件吧,比如给女朋友写情书什么的,写信的过程大家都还记得吧,先写信的内容,然后写信封,然后把信放到信封中,封好,投递到信箱中进行邮递,这个过程还是比较 ...
- Git客户端安装
Git介绍 分布式 : Git版本控制系统是一个分布式的系统, 是用来保存工程源代码历史状态的命令行工具; 保存点 : Git的保存点可以追踪源码中的文件, 并能得到某一个时间点上的整个工程项目额状态 ...
- 请指出document load和document ready的区别?
共同点:这两种事件都代表的是页面文档加载时触发. 异同点: ready 事件的触发,表示文档结构已经加载完成(不包含图片等非文字媒体文件). onload 事件的触发,表示页面包含图片等文件在内的所有 ...
- SpringBoot使用JSP渲染页面
1.pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...
- 【React Native开发】React Native For Android环境配置以及第一个实例(1)
年9月15日也公布了ReactNative for Android,尽管Android版本号的项目公布比較迟,可是也没有阻挡了广大开发人员的热情.能够这样讲在2015年移动平台市场上有两个方向技术研究 ...