Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 288677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:50:20+00:00 2026-05-12T05:50:20+00:00

I created a simple extension method for the ASP.NET MVC UrlHelper. It takes no

  • 0

I created a simple extension method for the ASP.NET MVC UrlHelper. It takes no arguments as its job is to look up the name of a stylesheet file from the configuration and return a url to the stylesheet. The extension method looks roughly like this:

public static string SiteStylesheet(this UrlHelper urlHelper)
{
    var scriptFilename = UserInterfaceConfiguration.GetSection()
                             .Mvc.SiteStylesheet;
    return urlHelper.Content(string.Format("~/Assets/Scripts/{0}",
                                           scriptFilename));
}

And I use it like this:

<link href="<%= Url.SiteStylesheet() %>" rel="Stylesheet" type="text/css" />

The method does not get executed, however, and the following is rendered:

href="../Views/Shared/%3C%25=%20Url.SiteStylesheet()%20%25%3E"

As you can see the extension method is not executed, rather the entire thing is just encoded. If I change the method signature to accept a parameter:

public static string SiteStylesheet(this UrlHelper urlHelper, string dummy)

then the extension method is executed and the output is as expected:

href="/Assets/Stylesheets/FluidCMS.css"

So my question then is this by design or is this a bug in the ASP.NET MVC Web Form view engine?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:50:21+00:00Added an answer on May 12, 2026 at 5:50 am

    This issue has come up a number of times. The root of the issue is that the <head> tag has runat=”server”, which causes the parser to treat tags as server tags.

    The simplest workaround is to just remove runat=”server” from the head tag. What you lose is the logic that makes the link URL’s relative to the current page, but since you’re using your helper anyway, you have no need for this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple Asp.Net custom control which automatically combines all the correct
I've created a simple extension method on the string type: public static bool Contains(this
I've created a simple extension method on the string type: public static bool Contains(this
I created a simple .NET windows application in Visual Studio 2005 and on just
I'm trying to add an extension method to my MVC 2 project without success
I am using ASP.NET MVC 2 Preview 2 and have written a custom HtmlHelper
I'm writing a new asp.net mvc application and I've been toying with the idea
I created a simple dialog-based application, and in the default CDialog added three buttons
I've created a simple desktop application in C# 3.0 to learn some C#, wpf
I've created a simple httpModule, registered it on GAC and added it to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.