我究竟做错了什么? (Razor Syntax& WebSecurity)

时间:2011-03-18 05:54:09

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

我正在使用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(“电子邮件”,新的等)控件完成了这项工作。但它仍然会产生同样的错误。这是怎么回事?我没有在这里看到问题。页面的其余部分只是静态HTML,在我放入WebSecurity之前工作正常。

感谢任何帮助

谢谢!

1 个答案:

答案 0 :(得分:2)

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