NET Core MVC 2.1中RedirectToAction的怪异行为

时间:2018-12-21 07:32:18

标签: c# asp.net-core asp.net-core-mvc

我在同一解决方案中有2个项目。尝试更改成功的登录重定向页面时,我尝试过redirectToAction。 (仅需清除下面的代码即可用于一个项目,但不适用于另一个项目)

import math
from decimal import Decimal

n = int(input('How often do you want your interest to be calculated: '))
p = int(input("Enter the principle amount:"))
t = Decimal(input("Enter the time(years):"))
r = Decimal(input("Enter the rate (in decimals for e.g 5% means 0.05):"))
#simple interest = P(1 + rt)
simple_interest=round((p*(1+ (r*t))))
print("The simple interest is:",simple_interest)
#compound interest = P(1 + r/n)nt, where n can be daily monthly or yearly (frequency)
#decimal.Decimal(4)
x = (round((p*(1 + (Decimal(r)/Decimal(n)))),2))
print('x value is ', x)
y = (round((n*t),2))
print('y value is ', y)
compound_interest = x**y
print ('The compund interest is: ' ,compound_interest)

这是登录名和重定向链接的链接

https://localhost:44343/Identity/Account/Login

https://localhost:44343/ControllerName

但是,在另一个项目中执行完全相同的操作时,它似乎不起作用。据我所知,项目配置是相同的。

https://localhost:44343/Identity/Account/Login

https://localhost:44343/Identity/ControllerName

编辑:这是问题。^它引用的页面不存在。它以某种方式在1个项目中可以正常工作,但是我必须在第二个项目中添加一个额外的area参数才能使其正常工作。

最终经过一些挖掘和引用 post,我修改了代码以包含新区域。

if (result.Succeeded)
{
    _logger.LogInformation("User logged in.");
    //return LocalRedirect(returnUrl);
    return RedirectToAction("Index", "ControllerName");
 }

请问有什么好心的人解释为什么会这样吗?非常感谢你!

项目1中的RouteConfig:

{
    _logger.LogInformation("User logged in.");
    //return LocalRedirect(returnUrl);
    return RedirectToAction("Index", "Competitions", new { area = "" });
}

项目2中的RouteConfig:

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

0 个答案:

没有答案
相关问题