路径中的非法字符.C#LoadControl

Cha*_*amp 0 c# sitecore sitecore6

我是C#的新手,正在使用sitecore开展项目

我刚刚添加了一个aspx页面

.aspx文件:

 <sc:sublayout runat="server" renderingid="{7ACDFB04-E9C9-4AC4-BDC6-6F3FF0862199}" path="/layouts/FSB/Header.ascx" id="HeaderFixed"></sc:sublayout>
    <sc:placeholder runat="server" key="layout" id="templatePage"></sc:placeholder>
    <sc:sublayout runat="server" renderingid="{621A56F6-9948-4661-9F33-3AFEF1DE698D}" path="/layouts/FSB/Footer.ascx" id="FooterFixed"></sc:sublayout> 
Run Code Online (Sandbox Code Playgroud)

.cs文件

 Control templateControl = LoadControl("templateLandingPages/free_template.ascx");
 Control placeHolderControl = Page.FindControl("templatePage");
Run Code Online (Sandbox Code Playgroud)

第16行的浏览器显示错误:

    Illegal characters in path.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentException: Illegal characters in path.

Source Error: 

Line 14:    protected void Page_Load(object sender, EventArgs e)
Line 15:    {
Line 16:     Control templateControl = LoadControl("templateLandingPages\free_template.ascx");
Line 17:     Control placeHolderControl = Page.FindControl("templatePage");
Run Code Online (Sandbox Code Playgroud)

Mic*_*kus 8

关于你如何使用你的简单问题\.你需要加倍斜杠(\\).第一个充当第二个的转义字符.

Control templateControl = LoadControl("templateLandingPages\\free_template.ascx");
Run Code Online (Sandbox Code Playgroud)

如评论,您还可以使用:

Control templateControl = LoadControl(@"templateLandingPages\free_template.ascx");
Run Code Online (Sandbox Code Playgroud)

查看关于字符串文字的这篇文章以及为什么要使用一种符号而不是另一种符号.