0

The web application is .Net 4.0 and is part Web Form's, part MVC. Rather than accessing the styles directly, the site uses an handler. Here is the real link:

<link href="@Url.Content("~/Styles/CssManager.ashx?s=StyleSheetName")" rel="stylesheet" type="text/css" />
<link href="~/Styles/CssManager.ashx?s=StyleSheetName" rel="stylesheet" type="text/css" />

Ideally I would like to use this URL:

<link href="@Url.Content("~/Styles/StyleSheetName.css")" rel="stylesheet" type="text/css" />
<link href="~/Styles/StyleSheetName.css" rel="stylesheet" type="text/css" />

The main reason is so the browser will catch the page. Can this be done by adding a route to the RouteCollection or must one go to IIS? I am trying to avoid the later, fore this is an intranet application we sell to our customers, who often know little about this stuff, so I am trying to keep it as simple as possible for them.


Q1: am I replacing this with an action?

A1: I had not thought of that, is it an option? (I updated the examples to be both web forms and mvc.

1
  • 1
    Can you replace the ASHX with an MVC action? Commented Aug 13, 2012 at 16:57

1 Answer 1

1

You could create custom IRouteHandler:

public class CssManagerHttpHandlerRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        CssManager handler = new CssManager();
        HttpContext.Current.Items["s"] = requestContext.RouteData.Values["s"];

        return handler;
    }
}

and then map it in your global.asax.cs file:

routes.Add(new Route("Styles/StyleSheetName.css", 
            new RouteValueDictionary { { "s", "StyleSheetName" } },
            new CssManagerHttpHandlerRouteHandler()));

However, you cannot change HttpContext.Request.QueryString or any other request-params collections. So the most "clear" way to pass arguements from RequestContext to HttpContext is use HttpContext.Current.Items collection. This might require some changes in your CssManager handler class.

You may also want to see this article.

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.