代码之家  ›  专栏  ›  技术社区  ›  XVargas

Internet Explorer发布数据错误-ASP.NET MVC

  •  0
  • XVargas  · 技术社区  · 15 年前

    我刚开始玩MVC,遇到了障碍。我使用一个局部视图作为用户登录弹出按钮,在每个页面的标题上使用OpenID。当用户单击提供程序(类似于stackoverflow)时,它会进行身份验证,然后返回调用页或重定向到注册页。该代码在Firefox和Chrome下运行无误,但在IE中会爆炸。控制器中的“provider”参数始终以空值发送。有没有在IE中发布输入名称/值的错误,或者我做错了什么?

    这就是我的OpenID部分视图的样子:

    <%  using (Html.BeginForm("Authenticate", "Membership", new { ReturnUrl = Request.Url }, FormMethod.Post))
    { 
        if (!Page.User.Identity.IsAuthenticated)
           { %>
                <div class="openidProviders">
                    Log in or join using one of these OpenID providers:
                    <div class="large buttons">                 
                        <div class="provider"><div><%= Html.SubmitImage("provider", "/Content/common/images/google.gif", new { value = "Google" })%></div></div>
                        <div class="provider"><div><%= Html.SubmitImage("provider", "/Content/common/images/Yahoo.gif", new { value = "Yahoo" })%></div></div>
                        <div class="provider"><div><%= Html.SubmitImage("provider", "/Content/common/images/AOL.gif", new { value = "AOL" })%></div></div>
                        <div class="provider"><div><%= Html.SubmitImage("provider", "/Content/common/images/OpenId.gif", new { value = "OpenId" })%></div></div>
                    </div>                      
                </div>                                          
        <% }       
    }
    %>
    

    控制器逻辑如下:

    [AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]        
    public void Authenticate(string provider, string ReturnUrl)
    {
        // Figure out provider endpoint
        // Authentication function calls here
    }
    
    1 回复  |  直到 15 年前
        1
  •  3
  •   XVargas    15 年前

    嗯,它看起来像IE,这一次,是唯一一个正确遵循HTML规范的浏览器 this post.

    HTML规范只要求 X,Y坐标 已单击“提交”按钮发送到 Web服务器。IE遵循 规范。发送的浏览器 值“…”参数正在执行 他们自己的东西在HTML之外 规范。

    基本上,我需要使用提交输入而不是提交,然后相应地设置按钮的背景样式。不是最佳解决方案,但至少它是有效的。这就是最终的解决方案。如果有人知道如何让下属正常工作,请告诉我。

    将上面的按钮替换为如下所示的按钮:

    <input type="submit" value="Google" class="google_OpenID" name="provider" />
    

    和CSS类:

    .google_OpenID
    {
        background-image: url(/Content/common/images/google.gif); 
        width:75px; 
        cursor:pointer; 
        color:transparent; 
        height:35px; 
        border:none;
    }