1

我有一个在 Visual Studio 中工作的 MVC3 应用程序,但是当发布到 Web 服务器时,在请求的 URL 上返回 404:/App/Account/LogOn。问题是我从未创建过帐户控制器或操作 LogOn。我不确定为什么 Account/LogOn 甚至正在加载或如何修复它。谢谢。

我的 global.asax.cs 文件如下所示:

public class MvcApplication : NinjectHttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        //filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", 
            "{controller}/{action}/{id}", 
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
        );

    }

    // Create ninject kernel
    protected override IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        // Add bindings
        kernel.Bind<IEmployeeRepository>().To<EFEmployeeRepository>();
        kernel.Bind<IDocumentRepository>().To<DocumentRepository>();
        // Load kernel
        kernel.Load(Assembly.GetExecutingAssembly());
        return kernel;
    }

    // Replaces App_Start() when using Ninject
    protected override void OnApplicationStarted()
    {
        base.OnApplicationStarted();
        AreaRegistration.RegisterAllAreas();
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
}
4

1 回答 1

1

我最好的猜测是这来自您的 web.config,因为这是您创建新 MVC 项目时的默认登录页面。当您尝试点击[Authorize]应用了该属性的操作时,您会被重定向到该位置。

检查一个部分说:

   <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

如果您有自己的登录页面,则需要在此处访问该 URL,否则,如果您没有使用安全性,请检查带有该[Authorize]属性的操作。

于 2011-09-14T13:36:43.627 回答