0、Program.cs

  1. using System.IO;
  2. using Microsoft.AspNetCore.Hosting;
  3.  
  4. namespace AspNetCoreUrlRoutingDemoRC2
  5. {
  6. public class Program
  7. {
  8. public static void Main(string[] args)
  9. {
  10. var host = new WebHostBuilder()
  11. .UseKestrel()
  12. .UseContentRoot(Directory.GetCurrentDirectory())
  13. .UseIISIntegration()
  14. .UseStartup<Startup>()
  15. .Build();
  16.  
  17. host.Run();
  18. }
  19. }
  20. }

1、project.json

  1. {
  2. "userSecretsId": "aspnet-WebApplicationCore1-782de49b-8e7f-46be-82aa-0f48e1d370bc",
  3. "dependencies": {
  4. "Microsoft.NETCore.App": {
  5. "version": "1.0.0-rc2-3002702",
  6. "type": "platform"
  7. },
  8. "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
  9. "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
  10. "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
  11. "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
  12. "Microsoft.AspNetCore.Routing": "1.0.0-rc2-final",
  13. "Microsoft.AspNetCore.Routing.Abstractions": "1.0.0-rc2-final",
  14. "Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-final",
  15. "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
  16. "Microsoft.Extensions.Configuration": "1.0.0-rc2-final",
  17. "Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
  18. "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
  19. "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc2-final",
  20. "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
  21. "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
  22. "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
  23. "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
  24. "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
  25. "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
  26. "Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
  27. "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final"
  28. },
  29.  
  30. "tools": {
  31. "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
  32. "version": "1.0.0-preview1-final",
  33. "imports": "portable-net45+win8+dnxcore50"
  34. }
  35. },
  36.  
  37. "frameworks": {
  38. "netcoreapp1.0": {
  39. "imports": [
  40. "dotnet5.6",
  41. "dnxcore50",
  42. "portable-net45+win8"
  43. ]
  44. }
  45. },
  46.  
  47. "buildOptions": {
  48. "emitEntryPoint": true,
  49. "preserveCompilationContext": true
  50. },
  51.  
  52. "runtimeOptions": {
  53. "gcServer": true
  54. },
  55.  
  56. "publishOptions": {
  57. "include": [
  58. "wwwroot",
  59. "web.config"
  60. ]
  61. },
  62.  
  63. "scripts": {
  64. "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  65. }
  66. }

2、appsettings.json

  1. {
  2. "ConnectionStrings": {
  3. "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplicationCore1-782de49b-8e7f-46be-82aa-0f48e1d370bc;Trusted_Connection=True;MultipleActiveResultSets=true"
  4. },
  5. "Logging": {
  6. "IncludeScopes": false,
  7. "LogLevel": {
  8. "Default": "Debug",
  9. "System": "Information",
  10. "Microsoft": "Information"
  11. }
  12. }
  13. }

3、Startup.cs

  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.AspNetCore.Routing;
  5. using Microsoft.AspNetCore.Hosting;
  6. using Microsoft.Extensions.Logging;
  7. using AspNetCoreUrlRoutingDemoRC2.PageRoute;
  8.  
  9. namespace AspNetCoreUrlRoutingDemoRC2
  10. {
  11. public class Startup
  12. {
  13. public Startup(IHostingEnvironment env)
  14. {
  15. IConfigurationBuilder builder = new ConfigurationBuilder()
  16. .SetBasePath(env.ContentRootPath)
  17. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  18. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  19.  
  20. if (env.IsDevelopment())
  21. {
  22. // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
  23. builder.AddUserSecrets();//project.json -> userSecretsId
  24. }
  25.  
  26. builder.AddEnvironmentVariables();
  27. this.Configuration = builder.Build();
  28. }
  29.  
  30. public IConfigurationRoot Configuration { get; }
  31.  
  32. // This method gets called by the runtime. Use this method to add services to the container.
  33. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
  34. public void ConfigureServices(IServiceCollection services)
  35. {
  36. services.AddRouting();
  37. }
  38.  
  39. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  40. {
  41. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  42. loggerFactory.AddDebug();
  43.  
  44. if (env.IsDevelopment())
  45. {
  46. app.UseDeveloperExceptionPage();
  47. app.UseBrowserLink();
  48. }
  49. else
  50. {
  51. app.UseExceptionHandler("/error");
  52. }
  53.  
  54. app.UseStaticFiles();
  55. //app.UseIdentity();
  56.  
  57. RouteBuilder routeBuilder = new RouteBuilder(app);
  58.  
  59. //index
  60. routeBuilder.DefaultHandler = new IndexPageRouteHandler(this.Configuration, "index");
  61. routeBuilder.MapRoute("index_culture_", "{culture}/", new RouteValueDictionary { { "culture", "en" } }, new RouteValueDictionary { { "culture", @"\w{2}" } });
  62. app.UseRouter(routeBuilder.Build());
  63.  
  64. //category
  65. routeBuilder.DefaultHandler = new CategoryPageRouteHandler(this.Configuration, "category");
  66. routeBuilder.MapRoute("category_", "{culture}/fashion/{leimu}/{pageindex}/", new RouteValueDictionary { { "pageindex", "" }, { "culture", "en" } }, new RouteValueDictionary { { "leimu", "([\\w|-]+)(\\d+)" }, { "pageindex", "\\d+" }, { "culture", @"\w{2}" } });
  67.  
  68. app.UseRouter(routeBuilder.Build());
  69.  
  70. }
  71. }
  72. }

4、IndexPageRouteHandler.cs

  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.AspNetCore.Routing;
  5. using Microsoft.AspNetCore.Http;
  6. using System.Diagnostics;
  7.  
  8. namespace AspNetCoreUrlRoutingDemoRC2.PageRoute
  9. {
  10. public class IndexPageRouteHandler : IRouter
  11. {
  12. private string _name = null;
  13. private readonly IConfigurationRoot _configurationRoot;
  14.  
  15. public IndexPageRouteHandler(IConfigurationRoot configurationRoot, string name)
  16. {
  17. this._configurationRoot = configurationRoot;
  18. this._name = name;
  19. }
  20.  
  21. public async Task RouteAsync(RouteContext context)
  22. {
  23. if (this._configurationRoot != null)
  24. {
  25. string connectionString = this._configurationRoot.GetConnectionString("DefaultConnection");
  26. Debug.WriteLine(connectionString);
  27. }
  28.  
  29. var routeValues = string.Join("", context.RouteData.Values);
  30. var message = String.Format("{0} Values={1} ", this._name, routeValues);
  31. await context.HttpContext.Response.WriteAsync(message);
  32. }
  33.  
  34. public VirtualPathData GetVirtualPath(VirtualPathContext context)
  35. {
  36. throw new NotImplementedException();
  37. }
  38. }
  39. }

5、CategoryPageRouteHandler.cs

  1. using Microsoft.AspNetCore.Routing;
  2. using System;
  3. using System.Threading.Tasks;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.Extensions.Configuration;
  6. using System.Diagnostics;
  7.  
  8. namespace AspNetCoreUrlRoutingDemoRC2.PageRoute
  9. {
  10. public class CategoryPageRouteHandler : IRouter
  11. {
  12. private string _name = null;
  13. private readonly IConfigurationRoot _configurationRoot;
  14.  
  15. public CategoryPageRouteHandler(IConfigurationRoot configurationRoot, string name)
  16. {
  17. this._configurationRoot = configurationRoot;
  18. this._name = name;
  19. }
  20.  
  21. public async Task RouteAsync(RouteContext context)
  22. {
  23. if (this._configurationRoot != null)
  24. {
  25. string connectionString = this._configurationRoot.GetConnectionString("DefaultConnection");
  26. Debug.WriteLine(connectionString);
  27. }
  28.  
  29. var routeValues = string.Join("", context.RouteData.Values);
  30. var message = String.Format("{0} Values={1} ", this._name, routeValues);
  31. await context.HttpContext.Response.WriteAsync(message);
  32. }
  33.  
  34. public VirtualPathData GetVirtualPath(VirtualPathContext context)
  35. {
  36. throw new NotImplementedException();
  37. }
  38. }
  39. }

6、F5启动调试,

浏览器输入网址:http://localhost:16924/

浏览器输入网址:http://localhost:16924/en/fashion/wwww-1111/2

6、VS2015项目结构

ASP.NET 5 RC 2:UrlRouting 设置(不包含MVC6的UrlRouting设置)的更多相关文章

  1. ASP.NET 5 RC 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)

    转自:http://habrahabr.ru/company/microsoft/blog/268037/?mobile=no 1.project.json { "version" ...

  2. ASP.NET Core 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)

    0.Program.cs using System.IO; using Microsoft.AspNetCore.Hosting; namespace WebApplication1 { public ...

  3. Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置

    解决思路: 1.找个可用的Aspose.Cells(有钱还是买个正版吧,谁开发个东西也不容易): 2.在.Net方案中引用此Cells: 3.写个函数ToExcel(传递一个DataTable),可以 ...

  4. 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头 ...

  5. Web.config中的设置 forms 中的slidingExpiration的设置

    在ASP.NET 网站中,使用 Forms Authentication时,一般的设置是如下的: <authentication mode="Forms"> <f ...

  6. 无线路由器的设置_不能通过wifi进行设置

    昨天朋友的小区宽带续费完不能上网了,过去看了一下,无线路由器没有问题,但是宽带信号没过来,网线直接插在电脑上用拨号,发现根本没办法连接,提示网线已经被拔出,重新还原一下系统,也是不行.因为之前他的电脑 ...

  7. 实现ScrollView中包含ListView,动态设置ListView的高度

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  8. iOS “请在微信客户端打开链接” UIWebview加载H5页面携带session、cookie、User-Agent信息 设置cookie、清除cookie、设置User-Agent

    公司新开的一个项目..内容基本上是加载H5页面显示..当时觉得挺简单的..后来发现自己掉坑里了..一些心理历程就不说了..说这个项目主要用到的知识点吧..也是自己踩得坑. 首先说说..这个项目上的内容 ...

  9. 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选

    设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...

随机推荐

  1. Cognos11中通过URL访问report的设置

    1:以往的cognos版本中在报表的属性中可以找到 url的属性,稍加修改就可以通过URL进行访问了 2:Cognos11中找了半天也没有报表URL这个属性,但是IBM官方也给出了解决方案 Answe ...

  2. 【算法】插入排序(Insertion Sort)

    (PS:内容参考MIT算法导论) 插入排序(Insertion Sort): 适用于数目较少的元素排序 伪代码(Pseudocode): 例子(Example): 符号(notation): 时间复杂 ...

  3. 扩展一个boot的插件—tooltip&做一个基于boot的表达验证

    在线演示 本地下载 (代码太多请查看原文) 加班,加班加班,我爱加班··· 我已经疯了,哦也. 这次发一个刚接触boot的时候用boot做的表单验证,我们扩展一下tooltip的插件,让他可以换颜色. ...

  4. .NET Framework System.Array.Sort 数组类,加深对 IComparer、IComparable 以及泛型委托、匿名方法、Lambda 表达式的理解

    本文内容 自定义类 Array.Sort 参考资料 System.Array.Sort 有很多对集合的操作,比如排序,查找,克隆等等,你可以利用这个类加深对 IComparer.IComparable ...

  5. Swift语言精要 - 扩展(Extension)

    swift的Extension用户在不访问代码的情况下扩展基本结构类型或自定义类 extension Int { var doubled : Int { } func multiplyWith(ano ...

  6. 微信小程序 - 深度定义骨架屏(提示)

    此举每个页面必须创建对应的css样式,比较麻烦(但非常准确),推荐使用组件化的skeleton组件 原理很简单:知晓一下this.setData原理,就OK了,可能大家会因此了解到全屏加载loadin ...

  7. 微信小程序 - 分包加载(独立分包)

    独立分包是小程序中一种特殊类型的分包,可以独立于主包和其他分包运行.从独立分包中页面进入小程序时,不需要下载主包.当用户进入普通分包或主包内页面时,主包才会被下载 将某些具有一定功能独立性的页面配置到 ...

  8. 使用Phantomjs和ChromeDriver添加Cookies的方法

    一.查看代码 : namespace ToutiaoSpider { class Program { static void Main(string[] args) { var db = Db.Get ...

  9. C#通过代码调用PowerShell

    var userId = "MyAccount@XXXXX.partner.onmschina.cn"; var tenantId = "XXXXX-ca13-4bcb- ...

  10. WorkFlow业务介绍

    WorkFlow简介 WorkFlow在我们的系统中,解释为系统提示更为恰当一下,当一件事情发生的时候可能需要通知某些人,这样其他人就可以做后续的处理了. 两个SST dts_workflow - W ...