在aspx中包含C#文件代码
我想在我的C#
页面上执行以下代码。 我知道这里有更多这样的问题,但我找不到可以帮助我的东西。 但是我在第一行遇到服务器错误
The server block is not well formed
代码是:
WebIntegrationRestService service= new WebIntegrationRestService(); service.GetUserByUsername(0,1,User.Identity.Name); UserType type = null; if (User.Identity.IsAuthenticated) { UserType type = service.GetUserByUsername(0, 1, User.Identity.Name).First().UserType; } if (type==UserType.TypeA) { %> <% }
你有不平衡的代码标签。
<%@ import Newtonsoft.Json.Linq; %> <%@ import System; %> <%@using Project.Models;%> <%@using Project.Controllers;%> <% WebIntegrationRestService service= new WebIntegrationRestService(); service.GetUserByUsername(0,1,User.Identity.Name); UserType type = null; if (User.Identity.IsAuthenticated) { UserType type = service.GetUserByUsername(0, 1, User.Identity.Name).First().UserType; } if (type==UserType.TypeA){%> <%: Html.ActionLink("Add User ", "Create", "User")%> <% } %>
请注意,我在页面级声明和代码开头之间添加了一个开始代码标记。
我还在最后一个结束后添加了一个。
你应该重新思考你在做什么。 当你开始在你的视图中放置这种东西时,你会遇到麻烦(维护视图,调试问题,重复代码等的维护成本)。