如何将C# .net实现路由映射到HTML页面?

2026-04-02 15:021阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计241个文字,预计阅读时间需要1分钟。

如何将C# .net实现路由映射到HTML页面?

1. ASP.NET 路由映射器可将请求路由到文件或控制器。尝试此示例:1. ASP.NET 路由映射器可将请求路由到文件或控制器。

1TheASP.NETroutemappercanroutetofilesorcontrollers.ASP.NET路由映射器可以路由到文件或控制器。Trythisexample:

1

The ASP.NET route mapper can route to files or controllers.

如何将C# .net实现路由映射到HTML页面?

ASP.NET路由映射器可以路由到文件或控制器。

Try this example: (you will need to rename your .html file to .aspx, but you dont have to make any other changes to it.)

試試這個例子:(您需要將.html文件重命名為.aspx但不必對其進行任何其他更改。)

In your route config file:

在您的路由配置文件中

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

// route default URL to index.aspx

routes.MapPageRoute(

routeName: "DefaultToHTML",

routeUrl: "",

physicalFile: "~/index.aspx",

checkPhysicalUrlAccess: false,

defaults: new RouteValueDictionary(),

constraints: new RouteValueDictionary { { "placeholder", ""} }

);

// other routes go here...

routes.MapRoute(

name: "Default",

url: "{controller}/{action}/{id}",

defaults: new { controller "Home", action "Index", id UrlParameter.Optional }

);

}

}

本文共计241个文字,预计阅读时间需要1分钟。

如何将C# .net实现路由映射到HTML页面?

1. ASP.NET 路由映射器可将请求路由到文件或控制器。尝试此示例:1. ASP.NET 路由映射器可将请求路由到文件或控制器。

1TheASP.NETroutemappercanroutetofilesorcontrollers.ASP.NET路由映射器可以路由到文件或控制器。Trythisexample:

1

The ASP.NET route mapper can route to files or controllers.

如何将C# .net实现路由映射到HTML页面?

ASP.NET路由映射器可以路由到文件或控制器。

Try this example: (you will need to rename your .html file to .aspx, but you dont have to make any other changes to it.)

試試這個例子:(您需要將.html文件重命名為.aspx但不必對其進行任何其他更改。)

In your route config file:

在您的路由配置文件中

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

// route default URL to index.aspx

routes.MapPageRoute(

routeName: "DefaultToHTML",

routeUrl: "",

physicalFile: "~/index.aspx",

checkPhysicalUrlAccess: false,

defaults: new RouteValueDictionary(),

constraints: new RouteValueDictionary { { "placeholder", ""} }

);

// other routes go here...

routes.MapRoute(

name: "Default",

url: "{controller}/{action}/{id}",

defaults: new { controller "Home", action "Index", id UrlParameter.Optional }

);

}

}