为f#asp.net核心项目配置启动文件时出现了奇怪的错误
我正试图开始一个ASP.NETF#项目,遵循mvc类型的模式 我使用的是rider IDE,因为我运行的是linux。rider IDE有现成的ASP.NET MVC模板,所以为了开始这个项目,我选择ASP.NET核心web应用程序模板 我现在有了一个为f#asp.net核心项目配置启动文件时出现了奇怪的错误,.net,asp.net-mvc,f#,.net,Asp.net Mvc,F#,我正试图开始一个ASP.NETF#项目,遵循mvc类型的模式 我使用的是rider IDE,因为我运行的是linux。rider IDE有现成的ASP.NET MVC模板,所以为了开始这个项目,我选择ASP.NET核心web应用程序模板 我现在有了一个Program.fs文件和一个Startup.fs,我可以运行项目并在浏览器中查看一个helloworld页面 但现在我想设置路由,以便可以路由到控制器 为此,我查看了一个C#MVC项目的框架,并尝试模拟Startup文件 我的启动文件现在如下所示
Program.fs
文件和一个Startup.fs
,我可以运行项目并在浏览器中查看一个helloworld页面
但现在我想设置路由,以便可以路由到控制器
为此,我查看了一个C#MVC项目的框架,并尝试模拟Startup
文件
我的启动文件现在如下所示:
namespace WebApplication1
open Microsoft.AspNetCore.Builder
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
type Startup() =
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
member _.ConfigureServices(services: IServiceCollection) =
services.AddAuthorization()
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
member _.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) =
if env.IsDevelopment() then
app.UseDeveloperExceptionPage() |> ignore
app.UseHttpsRedirection() |> ignore
app.UseStaticFiles() |> ignore
app.UseRouting() |> ignore
app.UseAuthorization)() |> ignore
app.UseEndpoints(fun endpoints ->
endpoints.MapControllerRoute("default","{controller=Home}/{action=Index}/{id?}" ) |> ignore
) |> ignore
现在,当我运行此命令时,我得到以下错误:
未处理的异常。System.InvalidOperationException:EndpointRoutingMiddleware与EndpointMiddleware设置的端点匹配,因此必须在EndpointMiddleware之前添加到请求执行管道。请通过在应用程序启动代码中对“Configure(…)”的调用中调用“iaapplicationbuilder.UseRouting”,添加EndpointRoutingMiddleware
所以它抱怨我没有在configure方法中调用iaapplicationbuilder.UseRouting
这对我来说很奇怪,因为我实际上正在打这样的电话
有人知道我如何重写它以启用到控制器的路由吗
编辑
有人向我指出,我缺少括号。我修复了这个问题,然后编译器通知我,ConfigureServices
中的services.AddAuthorization()
调用也丢失了。我现在修复了这个问题,上面的代码与我正在运行的代码一致
现在,当我运行它时,我得到:
Unhandled exception. System.InvalidOperationException: Unable to find the required services. Please add all the required services by calling
'IServiceCollection.AddAuthorization' inside the call to 'ConfigureServices(...)' in the application startup code.
这对我来说没有什么意义,因为我在
ConfigureServices
中有这样一个调用。一个问题是您的ConfigureServices
根本没有被调用,因为它的签名错误。请尝试以下方法:
member\uu.ConfigureServices(服务:IServiceCollection)=
services.AddAuthorization()|>忽略
不幸的是,
ignore
在这种情况下非常重要。本质上是一样的。您似乎忘记了括号:UseRouting()和UseAuthorization()