【问题标题】:404 with ASP.net MVC3 and ninject.web.mvc404 与 ASP.net MVC3 和 ninject.web.mvc
【发布时间】:2011-09-14 13:30:13
【问题描述】:

我有一个在 Visual Studio 中工作的 MVC3 应用程序,但是当发布到 Web 服务器时,在请求的 URL:/App/Account/LogOn 上返回 404。问题是我从未创建过帐户控制器或操作 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);
    }
}

【问题讨论】:

    标签: asp.net-mvc-3 ninject.web.mvc


    【解决方案1】:

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

    检查以下内容的部分:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多