1

I have a page Product.aspx that has a master page Main.master, both pages are in the root of the project (they don't belong to any folder). The problem is that the tilde path only works for the Main.master, not for products.aspx.

Main.Master:

<head>
    <!-- YOUR CUSTOM CSS -->
    <asp:ContentPlaceHolder ID="ContentHead" runat="server">
    </asp:ContentPlaceHolder>
</head>

products.aspx:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentHead" runat="server">
    <!-- SPECIFIC CSS -->
    <link href="~/css/product_page.css" rel="stylesheet">
    <!-- YOUR CUSTOM CSS -->
    <link href="~/css/custom.css" rel="stylesheet">
</asp:Content>

When I run the app, the html renders like this:

 http://localhost:49573/productos/alivio-de-presion/valvula-alivio-presion-vacio/~/css/product_page.css

I'm using for this page RouteTables in global.asax.cs:

RouteTable.Routes.MapPageRoute("infProds", "productos/{familia}/{nombre}", "~/Product.aspx");

As you can see, the tilde hasn't been translated. I have tried adding runat="server", but it throws an error

Content controls have to be top-level controls in a content page or a nested master page that references a master page

Since I can't add the runat="server" attribute, I cannot use functions like ResolveUrl. I believe there should be an easy way for this, because master pages are meant to work like this, I just don't understand how to deal with paths.

Thanks!

1 Answer 1

2

You can use an embedded code block to call the ResolveUrl method.

<asp:Content ID="Content1" ContentPlaceHolderID="ContentHead" runat="server">
    <!-- SPECIFIC CSS -->
    <link href='<%= ResolveUrl("~/css/product_page.css") %>' rel="stylesheet">
    <!-- YOUR CUSTOM CSS -->
    <link href='<%= ResolveUrl("~/css/custom.css") %>' rel="stylesheet">
</asp:Content>

Note the use of single quotes used on href to prevent the need to do nested double quotes since double quotes are used on the ResolveUrl call.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.