相关疑难解决方法(0)

Angular 2.0路由器无法重新加载浏览器

我使用的是Angular 2.0.0-alpha.30版本.当重定向到不同的路由,然后刷新浏览器,它显示无法GET /路由.

你能帮我弄清楚这个错误发生的原因吗?

angular2-routing angular

176
推荐指数
10
解决办法
10万
查看次数

包装StaticFileMiddleware以重定向404错误

我正在尝试将自定义中间件注入到我的OWIN管道中,该管道包装StaticFileMiddleware来自MS 的可用,以支持AngularJS中的HTML 5模式.我一直在关注这个指南:http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx

从我可以收集到的如何工作,我的中间件将请求传递给静态文件中间件,然后如果它无法解决这些请求(即,请求HTML 5角度路径,"/无论如何"),它返回基本角度页面,以便对HTML 5路径的硬请求将起作用.

我的问题是调用内部中间件的结果似乎总是200状态代码,即使在我的浏览器中我得到404,这让我挠头.这是我的代码供参考:

public static class AngularServerExtension
{
    public static IAppBuilder UseAngularServer(this IAppBuilder builder, string rootPath, string entryPath)
    {
        var options = new AngularServerOptions()
        {
            FileServerOptions = new FileServerOptions()
            {
                EnableDirectoryBrowsing = false,
                FileSystem = new PhysicalFileSystem(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rootPath))
            },
            EntryPath = new PathString(entryPath)
        };

        builder.UseDefaultFiles(options.FileServerOptions.DefaultFilesOptions);
        return builder.Use(new Func<AppFunc, AppFunc>(next => new AngularServerMiddleware(next, options).Invoke));           
    }
}

public class AngularServerMiddleware
{
    private readonly AngularServerOptions _options;
    private readonly AppFunc _next;
    private readonly StaticFileMiddleware _innerMiddleware; …
Run Code Online (Sandbox Code Playgroud)

asp.net angularjs owin

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

ASP.NET 5 HTML5历史

我正在将我的项目升级到ASPNET5.我的应用程序是使用HTML5 URL路由(HTML5历史记录API)的AngularJS Web App .

在我以前的应用程序中,我使用URL重写IIS模块,代码如下:

<system.webServer>
  <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_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
          <add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
        </conditions>
        <action type="Rewrite" url="Default.cshtml" />
      </rule>
    </rules>
  </rewrite>
<system.webServer>
Run Code Online (Sandbox Code Playgroud)

我意识到我可以移植它,但我想最小化我的Windows依赖项.从我的阅读中我认为我应该能够使用ASP.NET 5中间件来实现这一目标.

我认为代码看起来像这样但我觉得我相当遥远.

app.UseFileServer(new FileServerOptions
{
    EnableDefaultFiles = true,
    EnableDirectoryBrowsing = true
});

app.Use(async (context, next) =>
{
    if (context.Request.Path.HasValue && context.Request.Path.Value.Contains("api"))
    {
        await next();
    }
    else
    {
        var redirect …
Run Code Online (Sandbox Code Playgroud)

.net asp.net html5 asp.net-web-api-routing asp.net-core

8
推荐指数
2
解决办法
1560
查看次数

Angular 2 - 使用ASP.NET MVC进行路由

我试图使用ASP.NET MVC(不是核心)与AngularJS 2和路由的一些问题.

首先在RouteConfig.cs中,我定义了以下路由

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

// when the user types in a link handled by client side routing to the address bar 
// or refreshes the page, that triggers the server routing. The server should pass 
// that onto the client, so Angular can handle the route
routes.MapRoute(
    name: "spa-fallback",
    url: "{*url}",
    defaults: new { controller = "Home", action = "Index" } …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-4 angular-routing angular

7
推荐指数
2
解决办法
5603
查看次数