【问题标题】:What am I doing wrong? (Razor Syntax & WebSecurity)我究竟做错了什么? (Razor 语法和网络安全)
【发布时间】:2011-03-18 05:54:09
【问题描述】:

我正在使用 WebMatrix 实现 WebSecurity 功能,但它会在我的页面上产生错误!

这个错误对我来说毫无意义:

代码:

  <div class="signInOrRegister">

    @if(WebSecurity.IsAuthenticated)
    {
        <h1>@WebSecurity.CurrentUserName</h1>
        <p>You may view your Account Options by clicking <a href="#" class="ShowAccountToolbarAndMenu">View Account Options</a>
    }
    else
    {
        <h1>Sign In</h1>
        <p class="signInSummary">Already a Customer? Sign In here.</p>
        <div class="smallVerticalSpace"> </div>
        <form action="@Request.ServerVariables["URL"]" method="post">
          <table cellpadding="5" cellspacing="5" class="formTable">
            <tr>
              <td class="leftTD">
                <label for="email" class="UsernameLabel">E-mail Address:</label><br />
                <!--@Html.TextBox("Email", null, new { @class="email" })-->
              </td>
              <td class="rightTD">
                <label for="password" class="customerIdLabel">Password:</label><br />
                <!--@Html.Password("Password", null, new { @class="password"})-->
              </td>
              <td class="LastTD">
                <label for="rememberMe" class="rememberMeLabel">Remember me?</label><br />
                @Html.CheckBox("rememberMe")

                <input type="submit" class="submit" value="Sign In" />
              </td>
            </tr>
          </table>
        </form>
    }

  </div>

错误:

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: The if block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.


Source Error: 


Line 42:       <div class="signInOrRegister">
Line 43:         
Line 44:         @if(WebSecurity.IsAuthenticated)
Line 45:         {
Line 46:             <h1>@WebSecurity.CurrentUserName</h1>


Source File: /_SiteLayout.cshtml    Line: 44 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

因此,在阅读了错误之后,我确定没有任何内容被视为标记。我通过注释掉 @Html.TextBox("Email", new etc) 控件来做到这一点。但它仍然会产生同样的错误。这是怎么回事?我没有看到这里的问题。页面的其余部分只是静态 HTML,在我放入 WebSecurity 内容之前运行良好。

感谢任何帮助

谢谢!

【问题讨论】:

    标签: c# .net asp.net razor webmatrix


    【解决方案1】:

    尝试在你的 if 语句中关闭你的段落&lt;p&gt;(第 47 行)!这可能是错误的原因。

    【讨论】:

    • 天哪……我真是个笨蛋。我一直在到处寻找,但没有看到。谢谢!
    猜你喜欢
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2011-06-25
    • 2019-12-23
    • 2014-06-15
    • 1970-01-01
    相关资源
    最近更新 更多