AI智能
改变未来

Asp .net MVC的路由映射(伪静态)

后缀:html,jpeg等都可
RouteConfig设置

routes.MapMvcAttributeRoutes();routes.MapRoute(name: \"png\",url: \"{controller}/{action}.{后缀}\",defaults: new { controller = @\"[a-zA-Z]\", action = \"Index\" },namespaces: new string[] { \"{控制器名}\" });

Config中设置(不设置则IIS会不访问路由直接404)

<system.webServer><handlers><remove name=\"ExtensionlessUrlHandler-ISAPI-4.0_32bit\" /><remove name=\"ExtensionlessUrlHandler-ISAPI-4.0_64bit\" /><remove name=\"ExtensionlessUrlHandler-Integrated-4.0\" /><add name=\"ExtensionlessUrlHandler-ISAPI-4.0_32bit\" path=\"*.\" verb=\"GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS\" modules=\"IsapiModule\" scriptProcessor=\"%windir%\\Microsoft.NET\\Framework\\v4.0.30319\\aspnet_isapi.dll\" preCondition=\"classicMode,runtimeVersionv4.0,bitness32\" responseBufferLimit=\"0\" /><add name=\"ExtensionlessUrlHandler-ISAPI-4.0_64bit\" path=\"*.\" verb=\"GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS\" modules=\"IsapiModule\" scriptProcessor=\"%windir%\\Microsoft.NET\\Framework64\\v4.0.30319\\aspnet_isapi.dll\" preCondition=\"classicMode,runtimeVersionv4.0,bitness64\" responseBufferLimit=\"0\" /><add name=\"ExtensionlessUrlHandler-Integrated-4.0\" path=\"*.\" verb=\"GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS\" type=\"System.Web.Handlers.TransferRequestHandler\" preCondition=\"integratedMode,runtimeVersionv4.0\" /><add name=\"ExtensionlessUrlHandler-ISAPI-4.0_32bit2\" path=\"*.{后缀}\" verb=\"GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS\" modules=\"IsapiModule\" scriptProcessor=\"%windir%\\Microsoft.NET\\Framework\\v4.0.30319\\aspnet_isapi.dll\" preCondition=\"classicMode,runtimeVersionv4.0,bitness32\" responseBufferLimit=\"0\" /><add name=\"ExtensionlessUrlHandler-ISAPI-4.0_64bit2\" path=\"*.{后缀}\" verb=\"GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS\" modules=\"IsapiModule\" scriptProcessor=\"%windir%\\Microsoft.NET\\Framework64\\v4.0.30319\\aspnet_isapi.dll\" preCondition=\"classicMode,runtimeVersionv4.0,bitness64\" responseBufferLimit=\"0\" /><add name=\"ExtensionlessUrlHandler-Integrated-4.02\" path=\"*.{后缀}\" verb=\"GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS\" type=\"System.Web.Handlers.TransferRequestHandler\" preCondition=\"integratedMode,runtimeVersionv4.0\" /></handlers></system.webServer>
  • 点赞
  • 收藏
  • 分享
  • 文章举报

maotou526发布了8 篇原创文章 · 获赞 2 · 访问量 2814私信关注

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » Asp .net MVC的路由映射(伪静态)