简体   繁体   中英

Register Src attribute and block c# code within asp.net webform page

I have created this helper :

   public static class UrlHelper
    {

        public static string  SharedFolderUrl = "/template/";
        public static string  SpecificFolderSiteUrl = "/static/";

        public static string GetSharedFileUrl(this System.Web.UI.Control control, string fileurl)
        {
            return control.ResolveUrl(string.Concat(
                SharedFolderUrl,
                fileurl,
                string.Concat((fileurl.Contains("?") ? "&v=" : "?v="), _SiteVersion)
            ).Replace("//", "/"));
        }

}

So , in the home master page I tried to change this line :

<%@ Register TagPrefix="mscom" TagName="Wedcs" Src="/template/Wedcs.ascx" %>

by :

<%@ Register TagPrefix="mscom" TagName="Wedcs" Src="<%$ this.GetSharedFileUrl("controls/tracking/Wedcs.ascx")%>" %>

I have an error indicates that the format of this line is not correct.

I need to know how can I fix this issue?

Thanks,

What you are looking for is called VirtualPathProvider .

The concept is we could move aspx and ascx files outside of traditional folder, and find and render them dynamically. For example, store those in SQL Database or Azure Blob Storage.

ASP.NET Web Form is very mature technology, and you could easily google how to implement VirtualPathProvider.

I've resolved a lot of binding statement format issues by using single ticks when using something complex inside.

Instead of

<%@ Register TagPrefix="mscom" TagName="Wedcs" Src="<%$ this.GetSharedFileUrl("controls/tracking/Wedcs.ascx")%>" %>

You might try

<%@ Register TagPrefix="mscom" TagName="Wedcs" Src='<%$ this.GetSharedFileUrl("controls/tracking/Wedcs.ascx")%>' %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM