html5mode给出404未找​​到 [英] html5mode gives 404 not found

查看:140
本文介绍了html5mode给出404未找​​到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的AngularJS应用程序的URL删除#标签。我使用的Web API 2.0检索一些数据。这是我做了什么:

I'm trying to remove the hashtag from the URL in my AngularJS app. I'm using Web API 2.0 to retrieve some data. This is what I've done:

在我app.js

app.config(function($routeProvider, $locationProvider) {
        $routeProvider
            .when("/products", {
                templateUrl: "app/products/productListView.html"
            })
            .when("/products/:id", {
                templateUrl: "app/products/productInfoView.html" 
            })
            .otherwise({ redirectTo: "/products" });

        $locationProvider.html5Mode(true);
});

我还添加了<基本href =/方式> 我的 index.html的

当我去 HTTP它工作正常://本地主机:49767 / 并从那里通过链接进行导航

It works fine when I go to http://localhost:49767/ and navigate from there using links.

例如,点击产品带我到的http://本地主机:49767 /产品/ 5 和负载的信息就好了。但是,如果我直接去的http://本地主机:49767 /产品或直接连接到特定的产品我从IIS 404未找​​到错误。

For example, clicking a product takes me to http://localhost:49767/products/5 and loads the information just fine. However, if I go directly to http://localhost:49767/products or directly to a specific product I get 404 not found error from IIS.

我是什么失踪?

推荐答案

您必须配置您的服务器html5mode工作。

You have to configure your server to work with html5mode.

ASP.Net C#重写

在Global.asax中

In Global.asax

private const string ROOT_DOCUMENT = "/default.aspx";

protected void Application_BeginRequest( Object sender, EventArgs e )
{
    string url = Request.Url.LocalPath;
    if ( !System.IO.File.Exists( Context.Server.MapPath( url ) ) )
        Context.RewritePath( ROOT_DOCUMENT );
}

请参阅有关详细信息,此链接

这篇关于html5mode给出404未找​​到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆