我有幾個網頁API控制器的ASP.NET核心應用。我不知道是否有一定的聯繫,但應用程序與VS2015更新2創建的,現在我用VS2015更新工作3 所以我創造了另一個網絡API控制器,當有一個查詢,該控制器我有此異常:配置ASP.NET Core應用程序的正確順序是什麼?
System.NotSupportedException: The given path's format is not supported.
at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.Path.GetFullPath(String path)
at Microsoft.AspNet.FileProviders.PhysicalFileProvider.GetFullPath(String path)
at Microsoft.AspNet.FileProviders.PhysicalFileProvider.GetFileInfo(String subpath)
at Microsoft.AspNet.StaticFiles.StaticFileContext.LookupFileInfo()
at Microsoft.AspNet.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNet.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.Diagnostics.Entity.MigrationsEndPointMiddleware.<Invoke>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.Diagnostics.Entity.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Diagnostics.Entity.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
有趣的是,不知何故StaticFileMiddleware參與處理一個簡單的請求到控制器。雖然我可以通過改變配置的應用程序的順序調用
app.UseMvc(...
前
app.UseStaticFiles()
我還是想知道這是如何發生的解決這個問題,什麼是配置應用程序的正確順序。
請記住,所有以前添加控制器工作只是配置的兩種方式很好,但新人們只能與後者合作。
新的控制器不與靜態文件進行操作。
EDITED 路由: 在控制器:
[Route("api/[controller]")]
public class ViewsController : Controller
{
[HttpGet("{path}", Name = "Views")]
public async Task<IActionResult> Get(string path)
{
return Json("bla");
}
}
在Startup.cs:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "angular2app",
template: "ng/{*.}",
defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "api",
template: "api/{controller}/{action}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
陷入困境的請求:
http://localhost:5000/api/Views/blablapath
請從控制器發佈一些導致「麻煩」的代碼。 –
就是這樣。來自控制器的代碼不會造成任何麻煩,因爲調用永遠不會到達控制器。之前發生異常。 –
我之所以要求控制器代碼是因爲與以前的現有控制器相比,可能有些東西使它「特殊」。像路線註釋,特殊命名或其他... –