[英]Setting Routes in ASP.NET Core web application
I have this folder structure in my ASP.NET Core application:我的 ASP.NET Core 应用程序中有这个文件夹结构:
I am trying to set my routes using the following code:我正在尝试使用以下代码设置我的路线:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("Default", "{controller=Home}/{action=Index}/{id?}");
endpoints.MapGet("/", context =>
{
return Task.Run(() => context.Response.Redirect("/Home/Index"));
});
});
My default route is /Home/Index
but if the user is not authorized then I want to redirect him/her to /Login
and not /Home/Login
, the current code redirects to /Home/Login
, which doesn't exist!我的默认路由是/Home/Index
但如果用户未被授权,那么我想将他/她重定向到/Login
而不是/Home/Login
,当前代码重定向到/Home/Login
,它不存在!
What changes should I make in my code?我应该对我的代码进行哪些更改?
Everything is very strange, but it seems to me you can make it using attribute routing一切都很奇怪,但在我看来你可以使用属性路由来实现
[Route("~/Login")]
[Route("~/Home/Login")]
public IActionResult Login()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.