【发布时间】:2014-05-14 11:02:35
【问题描述】:
我想用 AngularJS 和 ASP.NET Web API 构建一个 SPA。
关于前端网页,我想尽可能地限制 asp.net 的含义,并将所有逻辑转移到 Angular 中,Web API 将提供的唯一东西是 REST 服务。
我创建了一个 index.html 页面,其中包含一些从服务器加载基本列表的角度。
但是我的index.html 是使用 ex 访问的。 http://localhost:1234/app/index.html,我现在想从http://localhost:1234/ 看到我的index.html,如果我从这个主机访问一些随机链接,也会得到一个自定义错误页面。
我需要 ASP.NET 来执行此操作吗?我想尽可能地限制 ASP.NET 的使用,只使用基本必需的东西。 我对此完全陌生。
Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<clear />
<add
name="StaticFile"
path="*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
</handlers>
<staticContent>
<mimeMap fileExtension=".*" mimeType="application/octet-stream" />
</staticContent>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="index.html"/>
</files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
还添加了路由:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
页面错误:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
【问题讨论】:
标签: c# javascript asp.net angularjs