简体   繁体   中英

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 ". I want the web server to return the exact same ~/Default.aspx page for all urls (not 404s). The url in the address bar must stay as /Employee/5 and not redirect to my base page. Then the javascript framework can route the url within my single-page-app.

I have the js client side already working (with pushState: true in my backbone.history.start - see Backbone routes without hashes? ).

// 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" }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM