[英]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.