简体   繁体   English

如何使 Asp.Net 服务器端路由与无哈希 url 一起工作? 例如对于 Backbone/AngularJS

[英]How do I make Asp.Net server-side routing work with hashless urls? eg for Backbone/AngularJS

For example instead of using " http://localhost/#/Employee/5 ", I want to go to " http://localhost/Employee/5 ".例如,我不想使用“ http://localhost/#/Employee/5 ”,而是转到“ http://localhost/Employee/5 ”。 I want the web server to return the exact same ~/Default.aspx page for all urls (not 404s).我希望 Web 服务器为所有 url(不是 404)返回完全相同的 ~/Default.aspx 页面。 The url in the address bar must stay as /Employee/5 and not redirect to my base page.地址栏中的 url 必须保持为 /Employee/5 并且不能重定向到我的基本页面。 Then the javascript framework can route the url within my single-page-app.然后 javascript 框架可以在我的单页应用程序中路由 url。

I have the js client side already working (with pushState: true in my backbone.history.start - see Backbone routes without hashes? ).我的 js 客户端已经在工作(在我的backbone.history.start 中使用 pushState: true - 请参阅没有哈希值的 Backbone 路由? )。

// Put any special route exceptions here, above the catch-all rule below
// eg a non-backbone login-page, ajax web service routes matching "api/{controller}/{action}/{id}".

routes.MapPageRoute(
    routeName: "SinglePageApp",
    routeUrl: "{*url}",
    physicalFile: "~/Default.aspx",
    checkPhysicalUrlAccess: false
);

// MVC version of the above ASPX version:
routes.MapRoute(
    name: "SinglePageApp",
    url: "{*url}",
    defaults: new { controller = "Home", action = "Index" }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET Core 3.1 MVC 中进行RequiredIf 客户端和服务器端验证? - How to make RequiredIf Client-side and server-side validation in ASP.NET Core 3.1 MVC? 您如何在ASP.NET中检测DOCTYPE(过渡或严格)服务器端? - How do you detect DOCTYPE (Transitional or Strict) server-side in ASP.NET? 如何使用ASP.NET MVC打印服务器端 - How to print server-side with asp.net mvc 如何使用 ASP.NET 删除浏览器的缓存服务器端? - How can I remove a browser's cache server-side, using ASP.NET? 在服务器端(控制器)进行验证是一种很好的做法吗? ASP.NET MVC - Is a good practice to make validation on server-side (controller) ? ASP.NET MVC 如何在ASP.NET中从客户端调用服务器端函数? - How to call server-side function from client-side in ASP.NET? 如何在服务器端捕获 ASP.NET Core 2 SignalR 异常并在客户端使用 JavaScript 处理它们? - How to catch ASP.NET Core 2 SignalR exceptions on server-side and handle them on client side with JavaScript? ASP.NET双列表框使用JQuery更新了客户端,以及如何在服务器端检索结果 - ASP.NET dual listboxes updated client-side with JQuery, and how to retrieve the results server-side 如何从客户端调用服务器端ASP.NET事件 - how to call a server-side ASP.NET event from the client-side ASP.NET Core中的服务器端图形 - Server-side graphics in ASP.NET Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM