This is a migrated thread and some comments may be shown as answers.

External CSS Different Domains

3 Answers 52 Views
Editor
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 03 May 2012, 10:15 PM
Is it possible to setup RadEditor to pull styles from a different domain? For example, taking your example from the help page:

<telerik:RadEditor runat="server" ID="RadEditor1">
    <CssFiles>
        <telerik:EditorCssFile Value="~/ExternalCssFiles/Styles1.css" />
        <telerik:EditorCssFile Value="~/ExternalCssFiles/Styles2.css" />
    </CssFiles>
</telerik:RadEditor>

Can I do something like this:

<telerik:RadEditor runat="server" ID="RadEditor1">
    <CssFiles>
        <telerik:EditorCssFile Value="http://www.mysite.com/styles/Styles1.css" />
        <telerik:EditorCssFile Value="http://www.mysite.com/styles/Styles2.css" />
    </CssFiles>
</telerik:RadEditor>

If not directly, do you have any recommendations on how I could implement something like this? I'm building a rather large CMS that will control content for multiple sites inside a single area and within the editor I would like for styles that show up to mimic the ones actually on the site being edited.

3 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 04 May 2012, 08:58 AM
Hello,

The css files from other domain scenario is not supported because due to potential vulnerabilities the browser security does not allow the javascript to read the styles from the different domain. You should always load styles from the same domain.

Please, see the following forum thread on the topic: http://www.telerik.com/community/forums/aspnet-ajax/editor/include-only-some-css-styles-in-dropdown.aspx.

All the best,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
digitall
Top achievements
Rank 1
answered on 04 May 2012, 05:52 PM
I had read that thread before posting and had hoped something had changed since then, but I can understand why it didn't. I was able to solve this though and get cross-domain stylesheets to load. The approach I took is linking the editor to an HTTP Handler that was local to my site and passed it a unique identifier (guid) in the query string like so:

this.RadEditor1.CssFiles.Add(new Telerik.Web.UI.EditorCssFile { Value = "~/cms/getstyles.ashx?app=" + this.CurrentApplication.Key.ToString() });

The handler then makes an HTTP web request to the external site to retrieve a specific stylesheet based on the guid in the query string. If a file is returned then the response is written out from the handler and my styles showed up. For those curious, here is the code for the handler:

var request = HttpWebRequest.Create(app.Url + "/_assets/styles/cms.css") as HttpWebRequest;
try
{
    if (request.GetResponse().ContentLength > 0 && request.GetResponse().ContentType == "text/css")
    {
        context.Response.ContentType = "text/css";
        using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
            context.Response.Write(reader.ReadToEnd());
 
        context.Response.End();
    }
}
//an empty response is returned for any web exceptions
catch (WebException) { }

The only additional thing I had to do was set the handler to never expire, otherwise subsequent requests to it would pull the cached version and not automatically reload it (such as when a style changes, is added, etc.). To do that, at the top of ProcessRequest(context) I added this:

context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetExpires(DateTime.MinValue);

Hopefully this solution can help anyone else who may need to support external styles!
0
Rumen
Telerik team
answered on 07 May 2012, 04:13 PM
Hello,

Thank you for sharing your solution with the community.

If you would like you can create a new code library on the subject and I will award you with Telerik points.

Greetings,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
digitall
Top achievements
Rank 1
Answers by
Rumen
Telerik team
digitall
Top achievements
Rank 1
Share this question
or