C# 无法设置调用控制器方法的路由
我无法设置到控制器方法的路由。我总是在浏览器中遇到以下错误:C# 无法设置调用控制器方法的路由,c#,asp.net,C#,Asp.net,我无法设置到控制器方法的路由。我总是在浏览器中遇到以下错误: <Error> <Message> No HTTP resource was found that matches the request URI 'http://localhost:8080/TextToSpeech'. </Message> <MessageDetail> No type was found that matches the controller named 'Tex
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:8080/TextToSpeech'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'TextToSpeech'.
</MessageDetail>
</Error>
以及应用程序:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}", new { action = "Get" });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
我将非常感谢你给我的建议
使现代化
我可以通过指定控制器所在的命名空间使其工作:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
我可以通过指定控制器所在的命名空间使其工作:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
尝试http://localhost:8080/TextToSpeech/Get?Hi @MohsinMehmood,谢谢你的回复。不,不幸的是,这个URL也不起作用。有了善良的礼遇,你就有了作为一个控制者的基础。试试这个:我建议你回答你自己的问题。这将使其他有同样问题的人更容易访问此问答。为什么您需要此:HttpSelfHostConfiguration。只需像api/TextToSpeech一样调用它