【问题标题】:ASP.NET 1.0 MVC APPLICATIONASP.NET 1.0 MVC 应用程序
【发布时间】:2010-06-24 19:14:13
【问题描述】:

使用 VS 2008 我创建了一个干净的 asp.net MVC 应用程序项目并且没有改变任何东西, 在我的电脑上一切正常。上传到服务器后,我遇到了问题。

LogOn.aspx页面代码来自VS2008 mvc应用模板,未经修改,

登录

登录

请输入您的用户名和密码。 如果您没有帐户。

<% using (Html.BeginForm()) { %>
    <div>
        <fieldset>
            <legend>Account Information</legend>
            <p>
                <label for="username">Username:</label>
                <%= Html.TextBox("username") %>
                <%= Html.ValidationMessage("username") %>
            </p>
            <p>
                <label for="password">Password:</label>
                <%= Html.Password("password") %>
                <%= Html.ValidationMessage("password") %>
            </p>
            <p>
                <%= Html.CheckBox("rememberMe") %> <label class="inline" for="rememberMe">Remember me?</label>
            </p>
            <p>
                <input type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
<% } %>

它可以在我的本地 asp.net 开发服务器和 GoDaddy 服务器上运行,但是当我将它移动到新的 Web 服务器时,它无法正常运行。

当我提交登录页面时,一个简单的 我本地机器上的页面一切正常,我和我得到:

Request URL:http://91.202.171.55/$sitepreview/powergroup.co.il/Account/LogOn
Request Method:GET
Status Code:200 OK
Request Headers
Referer:http://91.202.171.55/$sitepreview/powergroup.co.il/Account/LogOn
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4
Response Headers
Cache-Control:no-cache
Content-Length:2149
Content-Type:text/html; charset=utf-8
Date:Thu, 24 Jun 2010 18:51:43 GMT
Expires:Thu, 24 Jun 2010 18:51:44 GMT
Server:Microsoft-IIS/7.0
X-AspNet-Version:2.0.50727
X-AspNetMvc-Version:1.0
X-Powered-By:ASP.NET

但是在测试生产服务器时,页面并没有被提交,并且 AccountController LogOn 方法永远不会被调用。

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)

    {

        if (!ValidateLogOn(userName, password))
        {
            return View();
        }

        FormsAuth.SignIn(userName, rememberMe);
        if (!String.IsNullOrEmpty(returnUrl))
        {
            return Redirect(returnUrl);
        }
        else
        {
            return RedirectToAction("Index", "Home");
        }
    }

而是调用 AccountController LogOn GET 方法

public ActionResult LogOn()
    {

        return View();
    }

标题:

Request URL:http://91.202.171.55/$sitepreview/powergroup.co.il/Account/LogOn
Request Method:GET
Status Code:200 OK
Request Headers
Referer:http://91.202.171.55/$sitepreview/powergroup.co.il/Account/LogOn
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4
Response Headers
Cache-Control:no-cache
Content-Length:2149
Content-Type:text/html; charset=utf-8
Date:Thu, 24 Jun 2010 18:51:43 GMT
Expires:Thu, 24 Jun 2010 18:51:44 GMT
Server:Microsoft-IIS/7.0
X-AspNet-Version:2.0.50727
X-AspNetMvc-Version:1.0
X-Powered-By:ASP.NET

【问题讨论】:

  • 您如何知道 LogOn() 方法正在被调用,并且您没有陷入 LogOn(...) 方法的第一条语句?如果验证失败,它只会再次加载表单。服务器上的身份验证设置是否正确?
  • 因为请求总是以GET方式发送,还添加了一些调试日志

标签: asp.net asp.net-mvc


【解决方案1】:

只是快速检查一下,但实时服务器是否已针对 ISAPI 注册了 .mvc 扩展名?

【讨论】:

  • 我正在运行 IIS 7.0 - 需要注册吗?
【解决方案2】:

看起来您正在通过 GET 请求提交表单,而您要调用的 LogOn 操作方法由 AcceptVerbs(HttpVerbs.Post) 修饰,这使得可以调用操作方法以响应 POST 请求。只需像这样修改您的登录 FORM 标签:

<form ... method="post">

【讨论】:

  • 使用 (Html.BeginForm() 处理那个
猜你喜欢
  • 1970-01-01
  • 2011-03-25
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多