现有的asp.net项目没有新的控制器功能工作时,显示404 [英] Existing asp.net project no new controller function is working, showing 404

查看:81
本文介绍了现有的asp.net项目没有新的控制器功能工作时,显示404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的现有asp.net网站,我从客户端服务器上的code,其中的code托管。我能在我的本地PC运行项目,但是当我尝试添加新的控制器功能那么它只是显示HTTP 404。
![在这里输入的形象描述] [1]

I am working on existing asp.net website and I get the code from client server where the code was hosted. I was able to run the project in my local pc but when I try to add new controller function then it just show http 404. ![enter image description here][1]

例如在AccountController.cs有一个现有的登录功能

For example in AccountController.cs there was a existing login function

    // GET: /Account/Login

    [AllowAnonymous]
    public ActionResult Login(string returnUrl)
    {
        if (WebSecurity.IsAuthenticated == true){
            WebSecurity.Logout();
            Session.Abandon();
        }
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

然后我复制此功能并创建一个新的一样下方,也可复制视图文件并重新命名为

Then I copied this function and created a new one like below and also duplicated the view file and renamed

    //
    // GET: /Account/AaLogin
    [AllowAnonymous]
    public ActionResult AaLogin(string returnUrl)
    {
        if (WebSecurity.IsAuthenticated == true)
        {
            WebSecurity.Logout();
            Session.Abandon();
        }
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

的Global.asax.cs

Global.asax.cs

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new
            {
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
            });
        routes.MapRoute(
            "AaLogin", // Route name
            "Account/AaLogin", // URL with parameters
            new
            {
                controller = "Account",
                action = "AaLogin",
                id = UrlParameter.Optional
            });
    }

RouteConfig.cs

RouteConfig.cs

        public static void RegisterRoutes(RouteCollection routes) {

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "ViewListingNoAuth",
            url: "{id}",
            defaults: new { controller = "Listing", action = "PublicView"}
        );

        routes.MapRoute(
            name: "socialMediaHooks",
            url: "externalService/uploadFlyerToSocialMedia/{id}/{sName}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional }
        );

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

但它仍然当我浏览/帐号/ AaLogin不工作...任何机构可以帮助我在这个或任何资源,所以我能理解。

But it still doesn't work when I browse /Account/AaLogin... any body can help me in this or any resource so I can understand.

如果任何人都可以给我一个想法发生了什么,我会很开心的。

If anyone can give me a idea whats happening I would be very happy.

推荐答案

有些路线规则顺序只是改变就可以解决问题。我不得不做一次让我的应用程序查找路线。尝试改变你的的Global.asax.cs 文件的路径顺序。默认路由之前把登录路线。有时也可能是问题!

Some just changing the route rule order can solve the problem. i had to do it one time to get my application find the route. Try to change the route order in your Global.asax.cs file. Put the login route before the default route. sometime it could be the problem !

这篇关于现有的asp.net项目没有新的控制器功能工作时,显示404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆