【问题标题】:ASP MVC application not redirect to specifed Action MethodASP MVC 应用程序未重定向到指定的操作方法
【发布时间】:2015-05-28 05:25:10
【问题描述】:

我的登录控制器如下所示。

public class LogInController : Controller
{
    SchedulerContext schedulerContext = new SchedulerContext();

    [HttpGet]

    public ActionResult LogIn()
    {
        return View();
    }

    [HttpPost]
    public ActionResult LogIn(FormCollection frmCollection)
    {
        //Some Code

        return RedirectToAction("LogIn", "LogIn");
    }


    [HttpPost]
    public ActionResult SignUp(FormCollection frmCollection)
    {
        //Some Code

        return RedirectToAction("SignUpWizard", "SignUpWizard");
    }

}

我的登录控制器如下所示。

namespace Scheduler.Controllers.UserPanel
{
    public class SignUpWizardController : Controller
    {
        public ActionResult SignUpWizard()
        {
            return View();
        }
    }
}

我的视图看起来像这样。

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
    <link href="~/Content/css/main.css" rel="stylesheet" />
    <link href="~/Content/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/Content/js/jquery.js"></script>
</head>
<body>
    <nav class="navbar navbar-custom" role="navigation">
        <div class="container-fluid">
            <h2 class="text-center t-size-change">Login</h2>
        </div>
        <!-- /.container-fluid -->
    </nav>
    <div class="container m-t-150">
        <div class="row">
            <div class="col-md-12">
                <div class="login-tabs">
                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs nav-justified nav-tabs-custom" role="tablist">
                        <li class="active"><a href="#home" role="tab" data-toggle="tab">Login</a></li>
                        <li><a href="#profile" role="tab" data-toggle="tab">Sign up for free</a></li>
                    </ul>
                    <!-- Tab panes -->
                    <div class="tab-content">
                        <div class="tab-pane active custom-tab" id="home">
                            @using (Html.BeginForm("LogIn", "LogIn", FormMethod.Post))
                            {
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="form-group">
                                            <input type="email" placeholder="Email Address" class="form-control" name="Email" required>
                                        </div>
                                        <div class="form-group">
                                            <input type="password" placeholder="Password" class="form-control" name="Password" required>
                                        </div>
                                        <input type="submit" value="Login to Tucan Rotas" class="btn btn-success btn-custom" />
                                        <p class="text-center p-10"><a href="#">Forgot your password?</a></p>
                                    </div>
                                </div>
                            }
                        </div>
                        <div class="tab-pane custom-tab" id="profile">
                            @using (Html.BeginForm("SignUp", "LogIn", FormMethod.Post))
                            {
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="form-group">
                                            <input type="email" placeholder="Email Address" class="form-control" name="Email" required>
                                        </div>
                                        <div class="form-group">
                                            <input type="password" placeholder="Password" class="form-control" name="Password" required>
                                        </div>
                                        <input type="submit" class="btn btn-success btn-custom" value="Sign up for free" />
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/Content/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="~/Content/js/tab.js" type="text/javascript"></script>
</body>
</html>

当我按下登录或注册按钮时,应用程序调用 LogIn() 方法装饰 带有 HttpGet 属性。

当我的应用程序启动时 URL 看起来像这样。

http://localhost:56789/LogIn/LogIn?ReturnUrl=%2f

现在我尝试将 URL 更改为

http://localhost:56789/SignUpWizard/SignUpWizard

当我按 Enter 时,浏览器将应用程序重定向到 SignUpWizard 控制器并调用操作方法 SignUpWizard,但 URL 会自动更改为

http://localhost:56789/LogIn/LogIn?ReturnUrl=%2fSignUpWizard%2fSignUpWizard

请注意,除了 HttpGet 或 HttpPost 之外,我没有使用任何其他属性来装饰方法。我没有使用任何身份验证或授权。还尝试使用 AJAX.BeginForm() 以及 JQuery AJAX 调用提交日期。我没能解决问题。

昨天相同的应用程序使用相同的代码正常工作。

【问题讨论】:

  • 您可以发布您的 SignUpWizard 操作代码吗?
  • web.config 文件中有验证码吗?
  • 不,我试图从 web.config 中删除所有身份验证和授权代码。但它不起作用。
  • 请查找 SignUpWizard 控制器代码
  • 您的任何控制器或操作方法是否用 [Authorize] 属性修饰?

标签: asp.net asp.net-mvc asp.net-mvc-4 razorengine


【解决方案1】:
  1. 首先我停止 IIS 服务。
  2. 应用程序是否包含任何身份验证或授权代码?如果是,则将其删除。
  3. 删除 Bin 目录。
  4. 再次启动 IIS 服务。
  5. 再次运行应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多