简体   繁体   English

在ASP.Net Core MVC中未调用LoginController(在Visual Studio Code中)

[英]LoginController not being called in ASP.Net Core MVC (In Visual Studio Code)

I have following controller in asp.net core MVC. 我在asp.net核心MVC中具有以下控制器。

public class LoginController : Controller
    {
        public IActionResult Callback()
        {
            return View();
        }
    }

But when I load in URL like localhost:5000/login/callback. 但是当我在localhost:5000 / login / callback之类的URL中加载时。

It calls HomeController's Index Method. 它调用HomeController的Index Method。 What am I doing wrong? 我究竟做错了什么? In startup.cs I have following in Configure Method. 在startup.cs中,我在“配置方法”中有以下内容。

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });

Hey, Pals. 嘿,好朋友。 Thanks fo your answers. 谢谢您的回答。 I forgot to mention that I was running project in visual studio code. 我忘了提到我在Visual Studio代码中运行项目。 So when I ran project in vs2017, it is working now. 因此,当我在vs2017中运行项目时,它现在正在运行。 So may be this is build issue. 因此可能是构建问题。 So now question turns to how to build (or rebuild) project in visual studio code? 因此,现在的问题转向如何在Visual Studio代码中构建(或重建)项目?

You need to define Route for the controller. 您需要为控制器定义Route Then decorate action either by [HttpGet] or [HttpPost] 然后通过[HttpGet][HttpPost]装饰动作

[Route("api/MyLogin")]
public class LoginController : Controller
{
    [HttpGet]
    public IActionResult Callback()
    {
        return View();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Visual Studio 代码创建 Asp.net MVC 应用程序(非核心) - Create Asp.net MVC Application (not core) with visual studio code Visual Studio Code 调试默认的 ASP.NET Core MVC WebApp:不起作用 - Visual Studio Code debugging the default ASP.NET Core MVC WebApp: does not work 在 Visual Studio Code 中的 asp.net 核心 mvc 中实现 jquery 插件数据表 - Implementing jquery plugin datatable in asp.net core mvc in Visual Studio Code 在Visual Studio Code中调试多个ASP.NET Core项目 - Debug multiple ASP.NET Core projects in Visual Studio Code ASP.NET 核心 AuthorizationHandler 未被调用 - ASP.NET Core AuthorizationHandler not being called Visual Studio 2017 不会在 ASP.NET Core MVC 项目中创建新的空 MVC 控制器 - Visual Studio 2017 does not create a new empty MVC controller in ASP.NET Core MVC project Visual Studio Visual Studio MVC asp.NET Google Map - Visual Studio Visual Studio MVC asp.NET Google Map 如何从 asp.net 核心 5.0 中实体核心中的数据库更新 Visual Studio 代码中的模型 - How to update models in visual studio code from database in Entity Core in asp.net core 5.0 如何使用Visual Studio代码将实体框架核心安装到asp.net核心3项目 - How to install entity framework core to asp.net core 3 project using visual studio code 是否可以在 Visual Studio 中连接现有的本地数据库并使用 ASP.NET mvc Core 在 Web 上生成数据? - Is it possible to connect an existing local Database in Visual studio and generate the Data on Web with ASP.NET mvc Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM