相关疑难解决方法(0)

$ location /在html5和hashbang模式/链接重写之间切换

我的印象是Angular会重写在tempaltes中的锚标记的href属性中出现的URL,这样无论是在html5模式还是hashbang模式下它们都能正常工作.位置服务文档似乎说HTML链接重写处理了hashbang情况.因此,我希望在不在HTML5模式下,插入哈希值,并且在HTML5模式下,它们不会.

但是,似乎没有重写.以下示例不允许我只更改模式.应用程序中的所有链接都需要手动重写(或者在运行时从变量派生.我是否需要根据模式手动重写所有URL?

我没有在Angular 1.0.6,1.1.4或1.1.3中看到任何客户端URL重写.似乎所有href值都需要以#/为hashbang模式和/为html5模式.

是否有必要进行重写?我误读了文档吗?做些别傻话?

这是一个小例子:

<head>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.js"></script>
</head>

<body>
    <div ng-view></div>
    <script>
        angular.module('sample', [])
            .config(
        ['$routeProvider', '$locationProvider',
            function ($routeProvider, $locationProvider) {

                //commenting out this line (switching to hashbang mode) breaks the app
                //-- unless # is added to the templates
                $locationProvider.html5Mode(true);

                $routeProvider.when('/', {
                    template: 'this is home. go to <a href="/about"/>about</a>'
                });
                $routeProvider.when('/about', {
                    template: 'this is about. go to <a href="/"/>home</a'
                });
            }
        ])
            .run();
    </script>
</body>
Run Code Online (Sandbox Code Playgroud)

附录:在重新阅读我的问题时,我发现我使用了"重写"一词,但没有明确说明我何时以及何时进行重写.问题是如何让Angular在呈现路径时重写URL,以及如何在两种模式下统一解释JS代码中的路径.它不是关于如何使Web服务器执行HTML5兼容的请求重写.

angularjs angular-routing

179
推荐指数
2
解决办法
17万
查看次数

刷新页面显示"找不到页面"

我有一个应用程序,它使用单个ng视图和多个控制器和视图.如果我浏览根目录,例如:www.domain.com,一切正常.除非我按下Ctrl + R(刷新),否则它会给我404错误页面找不到.例如:在此页面刷新给我错误. http://domain.com/item/1/.

但是,如果我使用hashbang访问该页面,那么它将起作用.eg:http://domain.com/#!/ item1 /

我该如何解决这个问题?我的htacess是空的.我使用chrome支持html5 hashbang.

angularjs

45
推荐指数
3
解决办法
5万
查看次数

HTTP错误403.14 - 禁止Web服务器配置为不列出内容

我已经在位置C:\ Users\DEVESH\Desktop\Projects\MvcMusicStore-v3.0\MvcMusicStore-Completed\MvcMusicStore下载了MVC音乐商店ASP.NET应用程序,并在IIS上的同一位置添加了该网站.我也给了IIS_IUSRS许可,但是当我运行localhost时,我收到错误:

HTTP错误403.14 - 禁止Web服务器配置为不列出此目录的内容.

我用Google搜索了,但还没有找到解决办法.我做错了什么?

iis asp.net-mvc

39
推荐指数
8
解决办法
14万
查看次数

获取在IIS 7.5上运行的Angular2路由

我一直在学习Angular2.在nodejs lite-server上运行时,路由工作正常.我可以转到主(localhost:3000)页面并浏览应用程序.我也可以输入localhost:3000/employee,它将转到请求的页面.

该应用程序最终将存在于Windows IIS 7.5服务器上.如果我从主页面(localhost:2500)开始,路由工作正常,我可以在没有任何问题的情况下通过应用程序.我遇到问题的地方是尝试直接转到主登陆页面以外的页面(localhost:2500/employee).我收到HTTP错误404.0.

这是我的app.component文件,用于处理路由.

import { Component } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { HTTP_PROVIDERS } from '@angular/http';

import { UserService } from './services/users/user.service';
import { LogonComponent } from './components/logon/logon.component';
import { EmployeeComponent } from './components/employee/employee.component';


@Component({
     selector : 'opi-app',
     templateUrl : 'app/app.component.html',
     directives: [ROUTER_DIRECTIVES],
     providers: [ROUTER_PROVIDERS, UserService, HTTP_PROVIDERS]
})

@RouteConfig([
     {
      path: '/',
      name: 'Logon',
      component: LogonComponent,
      useAsDefault: true 
     },
     {
      path: '/employee',
      name: 'Employee',
      component: EmployeeComponent
     }
])

export class …
Run Code Online (Sandbox Code Playgroud)

html iis-7.5 angular

25
推荐指数
3
解决办法
2万
查看次数

使用启用了Html5模式的Angular Ui Router时,页面重新加载失败

我在我的角度应用程序中使用Angular UI路由器,我已启用HTML5模式,通过在配置中使用$ locationProvider删除#form的URL.

var app = angular.module('openIDC', ['ui.router']);
app.config(function($urlRouterProvider, $stateProvider, $locationProvider) {

    $locationProvider.html5Mode(true);

    $urlRouterProvider.otherwise('/');

    $stateProvider
    .state('home', {
        url: '/',
        templateUrl: 'views/home.html',
        controller: 'HomeController'
    })
    .state('login', {
        url: '/login', 
        templateUrl: 'views/login.html',
        controller: 'LoginController'
    })
});
Run Code Online (Sandbox Code Playgroud)

我也在<base href="/" />index.html文件中设置了标记.路由工作正常,我可以导航到页面并删除#但是当我使用浏览器上的重新加载按钮刷新页面时,会出现404错误响应.

在此输入图像描述

为什么会发生这种情况,如何解决这个问题并启用HTML5模式以获得正确的URL

javascript html5 angularjs angular-ui-router

15
推荐指数
2
解决办法
2万
查看次数

如何正确刷新在VS 2015 Web开发环境中运行的AngularJS SPA

我有一个AngularJS SPA应用程序,我使用Visual Studio 2015开发.当我点击发布它发布index.html并且工作得很好.但是,如果我在页面上并单击刷新,则会尝试刷新SPA页面,例如example.com/home/about.这失败了,因为我没有家/关于页面.

有没有办法可以修改我的web.config文件(仅用于本地测试),这样它实际上会转到index.html(加载它)然后转到/ home/about状态?

这是我当前的web.config:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

visual-studio angularjs

8
推荐指数
1
解决办法
277
查看次数

从IIS提供ember应用程序导致UnrecognizedURLError

我正在尝试从IIS提供一个ember应用程序.

我创建了一个新应用程序ember new my-app然后运行ember build --environment production.这会dist按预期生成目录中的文件.

在IIS方面,我在服务器上添加了一个新网站,并dist从最后一步映射了该文件夹.

现在,当我导航到localhost/index.html我得到一个空白页面.

我检查了页面的来源,并按预期正确地提供了js文件.这意味着它是未正确检索的模板.在chrome检查器控制台中有一个例外Uncaught: UnrecognizedURLError: /index.html.烬检查员说'未检测到Ember应用程序!'.

我已经尝试过这里提到的解决方案,但没有一个对我有用.

有没有其他人遇到过这个问题/知道如何解决这个问题?

javascript iis ember.js ember-cli

7
推荐指数
1
解决办法
1208
查看次数

IIS URL重写规则

我有一个AngularJS应用程序,它利用URL重写进行链接.我的重写规则如下:

<rewrite>
<rules> 
  <rule name="MainRule" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll">
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="^api/(.*)" negate="false" />
    </conditions>
    <action type="Rewrite" url="Default.cshtml" />
  </rule>
</rules>
Run Code Online (Sandbox Code Playgroud)

我在SO上找到了这个解决方案:如何在HTML5模式下为URL重写AngularJS应用程序配置IIS?并进行了一次修改以允许我的API通过.

基本上,我想将我的所有请求重定向Default.cshtml到我的Web API的EXCEPT调用.当我我加载在基础URL应用这个伟大的工程,如:localhost/myapp.但是,如果我在一个有角度的路线上重新加载页面:localhost/myapp/dashboard它失败说:

<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost/myapp/dashboard'.</Message>
<MessageDetail>No type was found that matches the controller named 'dashboard'.</MessageDetail></Error>
Run Code Online (Sandbox Code Playgroud)

我有一个解决方法:

 <rewrite>
  <rules>
    <rule name="Default" stopProcessing="true">
      <match url="^(?!lib|api|dist|assets|app/|bower|common|main|signalr|templates|bower_components/).*" />
      <action type="Rewrite" url="Default.cshtml" />
    </rule> …
Run Code Online (Sandbox Code Playgroud)

iis url-rewriting

6
推荐指数
1
解决办法
2667
查看次数

页面刷新后的cookie计数为零,并且使用url重写进行角度路由

我正在使用.net core 2.0和angular 4的角度Spa模板.

页面刷新后,我的cookie数量为零.事实上,在页面刷新后,我在HttpContext中没有得到任何东西.

这是我在浏览器中的cookie. 在此输入图像描述

如果我使用角度系统菜单,它工作正常.

现在,这是我在后端获取cookie的代码.

    private string GetCookie(HttpContext httpContext, string cookieName)
    {
        var rqstCookie = httpContext.Request.Cookies[cookieName];

        return !string.IsNullOrEmpty(rqstCookie) ? rqstCookie : null;
    }
Run Code Online (Sandbox Code Playgroud)

一个重要的事情是,当我点击菜单时,它会加载组件和服务文件,然后它向C#controller请求所有标题和选项.但是当我刷新页面时,整个过程都会被跳过,所以我认为这些选项不会传递到后端,这就是为什么我的cookie是空的.

在我的其他应用程序中,我已经使用url重写同样的问题,它在那里工作,但在这里,因为这个应用程序是角度spa模板,url重写不起作用.

我也尝试设置url重写,就像我在旧应用程序中所做的那样,但它给了我错误.这是我遵循的url重写模块的链接. /sf/answers/1830640801/

我已将Cookie更新为Session Cookie,但它也无效.

你能指导我如何获取所有的cookie和其他数据,即使用户刷新页面.谢谢...

single-page-application asp.net-core-2.0 angular spa-template

6
推荐指数
1
解决办法
225
查看次数

ASP.NET Core 中资源的相对 url 无法从开发到生产

我正在努力解决我的 ASP.NET Core 和 Angular 2 应用程序中的一个问题,它在开发中运行良好,但是当发布到 IIS 并为 ASP.NET Core 正确配置 IIS 时,它无法加载所需的样式表和脚本。

我将所有没有映射到我的 API 路由的请求通过返回一个VirtualFileResult. index.html 有一个

<!DOCTYPE html>
<html>
<head>
    <title>Data Platform</title>
    <meta name="description" content="Data Platform" />
    <meta charset="utf8" />

    <base href="/" />
    <link rel="stylesheet" href="lib/css/vendors.css" />
    <link rel="stylesheet" href="platform/content/css/base.css" />
    <link rel="stylesheet" href="platform/content/css/bootstrap-overrides.css" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />

    <script src="lib/vendors.js"></script>
    <script>
        System.config({
            packages: {
                "/platform/": { defaultExtension: "js" }
            }
        });

        System.import("/platform/boot");
    </script>
</head>
<body>
    <data-platform>Initializing...</data-platform>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Startup.cs配置是非常基本的:

app.UseIISPlatformHandler(); …
Run Code Online (Sandbox Code Playgroud)

iis asp.net-mvc relative-path asp.net-core angular

5
推荐指数
1
解决办法
6975
查看次数