Rakesh Jaimini
asked on
Get Aspx page content before sending to client
Hi,
We have implemented themes in our web application by using attached files
and <link href="CSS.Aspx" rel="stylesheet" type="text/css" />
we stores themes in db and have used <% %> in CSS.Aspx
depending upon the user themes settings is fetched from DB and appropriate variables are assigned values to the variables like 'TextBoxColor' in attached files.
everything works fine.
Now I need to export this dynamic css file or in simple words i need to save this CSS.Aspx on server side after <% %> is replaced by its value (file similar to attached RenderedCSS.css ) so that i can zip it and return to the user
I have used attached code but problem with this code is that it gives me CSS.Aspx file with <% %> but i want file similar to RenderedCSS.css
also i'm using .net 2.0 framework
P.S. Don't suggest me to change my approach of dynamic CSS(CSS.Aspx) with App_Themes approach because its not possible to change this in our project.
CSS.Aspx.cs.gif
RenderedCSS.css
We have implemented themes in our web application by using attached files
and <link href="CSS.Aspx" rel="stylesheet" type="text/css" />
we stores themes in db and have used <% %> in CSS.Aspx
depending upon the user themes settings is fetched from DB and appropriate variables are assigned values to the variables like 'TextBoxColor' in attached files.
everything works fine.
Now I need to export this dynamic css file or in simple words i need to save this CSS.Aspx on server side after <% %> is replaced by its value (file similar to attached RenderedCSS.css ) so that i can zip it and return to the user
I have used attached code but problem with this code is that it gives me CSS.Aspx file with <% %> but i want file similar to RenderedCSS.css
also i'm using .net 2.0 framework
P.S. Don't suggest me to change my approach of dynamic CSS(CSS.Aspx) with App_Themes approach because its not possible to change this in our project.
String inputFile = MapPath("../css/css.aspx");
String sDiskFile = "../temp/result.css";
WebRequest webRequest = WebRequest.Create(inputFile);
WebResponse webResponse = webRequest.GetResponse();
Stream stream = webResponse.GetResponseStream();
StreamReader oReader = new StreamReader(stream);
StreamWriter oWriter = new StreamWriter(Server.MapPath(sDiskFile));
oWriter.Write(oReader.ReadToEnd());
oWriter.Close();
oReader.Close();
webResponse.Close();
CSS.Aspx.gifCSS.Aspx.cs.gif
RenderedCSS.css
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
@miggety
nice thinking and surely approach will work but in my case this will require lot of rework,also if i create control then i need to create 4 5 controls as we supports all browsers
and have made separate files for each (IECSS.Aspx,FireFoxCSS.Asp x).
And most important i need to teach everyone in my team for this new approach which is most difficult job
so i'm dropping you approach :)
@azarc3
i have used "https://rakesh939/appname/css/css.aspx" but now i'm getting
"The remote certificate is invalid according to the validation procedure." exception
then i tried using http and put my file out of authorization and it worked
as our servers are running on https how can i remove exception while using https
@miggety
nice thinking and surely approach will work but in my case this will require lot of rework,also if i create control then i need to create 4 5 controls as we supports all browsers
and have made separate files for each (IECSS.Aspx,FireFoxCSS.Asp
And most important i need to teach everyone in my team for this new approach which is most difficult job
so i'm dropping you approach :)
@azarc3
i have used "https://rakesh939/appname/css/css.aspx" but now i'm getting
"The remote certificate is invalid according to the validation procedure." exception
then i tried using http and put my file out of authorization and it worked
as our servers are running on https how can i remove exception while using https
Question for you: is https://rakesh939/appname/css/css.aspx the full domain name? It needs to match what is listed in the certificate or you will most likely get the error.
These posts may help figure it out too...
http://blogs.msdn.com/jpsanders/archive/2009/09/16/troubleshooting-asp-net-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx
-- This one will probably fix the problem if the fully qualified domain name doesn't get rid of the exception.
http://forums.asp.net/t/905382.aspx
-- Look for the post by JohnAbot.
-- I assume you stick the handler call in the constructor of the class/page that makes the call to the service.
http://blogs.msdn.com/hongmeig/archive/2007/05/01/wcf-exception-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx
-- This post confirms what's said in the second one.
These posts may help figure it out too...
http://blogs.msdn.com/jpsanders/archive/2009/09/16/troubleshooting-asp-net-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx
-- This one will probably fix the problem if the fully qualified domain name doesn't get rid of the exception.
http://forums.asp.net/t/905382.aspx
-- Look for the post by JohnAbot.
-- I assume you stick the handler call in the constructor of the class/page that makes the call to the service.
http://blogs.msdn.com/hongmeig/archive/2007/05/01/wcf-exception-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx
-- This post confirms what's said in the second one.
1) create a class called CustomCSS that inherits from Control
namespace app
{
public class CustomCSS : Control
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write(".fieldvalue { text-align: left; font-family: \"areal\"; }");
writer.Write(".radiobtn { font-family:\"arial\"; font-size: 10px;");
.
.
.
// continue writing out the rest of your css file.
}
}
}
2) compile this control into a .dll named mycontrol
3) then in your web.config file place the following tag:
<controls>
<add tagPrefix="MyControls" namespace="app" assembly="mycontrols" />
</controls>
4) then your Css.aspx file should look this
<%@ Page Language="C#" Async="false" Trace="false">
<MyControls:CustomCSS ID="css" runat="server" />
since all of the content for this page comes from your control you can simply call the Render method to get the contents. Like this:
StringWriter stringwriter = new StringWriter();
HtmlTextWriter htmlwriter = new HtmlTextWriter(stringwrite
CustomCSS _customcss = new CustomCSS();
_customcss.Render(htmlwrit
string s = stringwriter.ToString();
I'm not sure if i answered your question or not, but hopefully that helps.
Mig