我想在浏览器中找到这个网址:
http://localhost:41359/account/login
以下是来自RouteConfig.cs的路线:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace CTHRC.Roti.Web.UI
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Account",
url: "account/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
但是当我尝试在浏览器中转到此URL时,我收到此错误:
{"Message":No HTTP resource was found that matches the request URI 'http://localhost:41359/account'.","MessageDetail":"No type was found that matches the controller named 'account'."}
一切似乎都在这里,但我仍然得到这个错误。这是我的AccountController:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;
using CTHRC.Roti.Domain.Api.Services;
namespace CTHRC.Roti.Web.UI.Controllers
{
public class AccountController : Controller
{
[HttpGet]
public ActionResult Login()
{
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("ModelContext", "Users", "Id", "UserName", autoCreateTables: true);
}
return View();
}
[HttpPost]
public ActionResult Login(FormCollection form)
{
bool success = WebSecurity.Login(form["username"], form["password"], false);
if (success)
{
string returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl == null)
{
Response.Redirect("/home/index?userID=" + WebSecurity.CurrentUserId);
}
else
{
Response.Redirect(returnUrl);
}
}
return View();
}
[HttpGet]
public ActionResult Register()
{
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("UserDb", "Users", "Id", "UserName", autoCreateTables: true);
}
return View();
}
[HttpPost]
public ActionResult Register(FormCollection form)
{
WebSecurity.CreateUserAndAccount(form["username"], form["password"], new { Email = form["email"], Language = form["language"] });
Response.Redirect("/account/login");
return View();
}
public ActionResult Logout()
{
WebSecurity.Logout();
Response.Redirect("/account/login");
return View();
}
}
}
我几天来一直在努力解决这个问题,我已经清理了我的解决方案,重新构建了我的解决方案并构建了我的解决方案,但我仍然遇到了这个错误。如果有人能帮助我,我将非常感激。提前致谢。