URL Parameters for Dynamic JS and CSS





10
Date Submitted Tue. Dec. 5th, 2006 2:15 PM
Revision 1 of 1
Scripter Casper42
Tags ASPX | CSharp | CSS | JavaScript
Comments 3 comments
This snippet allows an aspx page (c#) to accept URL parameters to allow styles or script to be dynamically appended to the rendered page.

I wrote this simple snippet to allow one of our vendors to accept a style override so that their application would morph into something more closely resembling our own portal application. Please see screenshots for clarification.

Original Vendor Application

Vendor Application with Style Override via URL

<%
    if (Request.Url.AbsoluteUri.ToLower().IndexOf("style")>-1)
    {
      string style= Request.QueryString["style"];
      Response.Write("<link rel='stylesheet' type='text/css' href='"+ style + "'/>");
    }

    if (Request.Url.AbsoluteUri.ToLower().IndexOf("script")>-1)
    {
      string script= Request.QueryString["script"];
      Response.Write("<script type='text/javascript' src='"+ script+ "'></script>");
    }

%>
 

Jeremy Edmiston

Comments

Comments A word of caution..
Wed. Dec. 6th, 2006 7:22 AM    Scripter Casper42
Comments XSS
Tue. Dec. 12th, 2006 4:51 AM    Scripter SCoon
Comments Did not consider that...
Tue. Dec. 12th, 2006 8:13 AM    Scripter Casper42

Voting