路由模板不能以“~”开头ASP.NET 中的字符
使用 Microsoft ASP.NET Core 框架和 C# 语言,我正在构建一个 Web REST 服务器,它必须响应路径以字符串“~app”开头的请求。所以,我写了这些行:
[ApiController]
[Route("~app")]
public class MyController : ControllerBase ...
但是,当执行以下行时:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
引发以下异常:
System.ArgumentException
HResult=0x80070057
Message=The route template cannot start with a '~' character unless followed by a '/'. (Parameter 'routeTemplate')
Inner Exception 1:
RoutePatternException: The route template cannot start with a '~' character unless followed by a '/'.
为什么请求路径中不允许使用波形符字符?
编辑:如何响应路径以字符串“~app”开头的请求?
Using the Microsoft ASP.NET Core framework and C# language, I am building a Web REST server, that must respond to requests whose path begins with the string "~app". So, I wrote these lines:
[ApiController]
[Route("~app")]
public class MyController : ControllerBase ...
Though, when the following lines are executed:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
the following exception is raised:
System.ArgumentException
HResult=0x80070057
Message=The route template cannot start with a '~' character unless followed by a '/'. (Parameter 'routeTemplate')
Inner Exception 1:
RoutePatternException: The route template cannot start with a '~' character unless followed by a '/'.
Why the tilde character is not allowed in the request path?
EDIT: How can I respond to requests whose path begins with the string "~app"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
开始时的
~
是 路由模板中的特殊字符(以及 这个)。以下代码将
[Route("[controller]/[action]")]
应用于控制器:~
at start is special character in route templates (and this).The following code applies
[Route("[controller]/[action]")]
to the controller: