日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

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

發布時間:2025/5/22 asp.net 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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设置)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。