Avoid browser cache in asp.net - asp.net

I try to disable the html url browser cache using programmatically.
I am developing as a site using asp.net, I need to disable the html url browser for the security reason.
I tried many ways to disable the cache but none seems to work. Any ideas?
<iframe id="iframe" src="http://www.phy.mtu.edu/basiccomputing/sample.html" runat ="server" width="200" height="300"></iframe>

As far as it's a html file you want to work with, a easy solution is to append a random number and the end of your url like this
<iframe id="iframe" src="http://www.phy.mtu.edu/basiccomputing/sample.html?12345" runat ="server" width="200" height="300"></iframe>
I don't know wich view engine you are using, so i cant provide a sample you simple copy and paste.
You have to replace ?12345with a random number like new Random().Next().ToString()
If you call a asp.net page you can control it with
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
more informations about that:
ASP.NET Cache Examples
hope this helps

You could attach a random parameter to the URL so the browser thinks it's a different page every time.
http://www.phy.mtu.edu/basiccomputing/sample.html?rand=[INSERT RANDOM HERE]

try
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)). This site has something that can be quite helpful.

Related

`a` tag with runat server and tilde in href

For example, I have two sibling pages Index.aspx and Orders.aspx in one folder. On the page Index.aspx I have the link to Orders.aspx. What is the correct way to implement this:
<a runat="server" href="~/Orders.aspx">
or
<a href="Orders.aspx">
I know what runat="server" does (server-control, performance impact etc.).
You really never need to run markup with a run at server tag if it's never used in code behind, if it is then you should use a ASP.NET control for it.
So just a hyperlink without runat=server would be fine.
It's always best to use ASP.NET controls on your page though if an upgrade in the future could require language translations, or have some logic assigned to them in the future. So always plan ahead on your designs.
If both views are in the same folder, than the second one:
<a href="Orders.aspx">

trying to disable the telerik editor control in asp

I was thinking to do this server side, but what i was wanting to do was disable the telerik control called the "Editor." Located at the site: telerick editor control.
My reasoning behind this was that I wanted to give a user the exact look and feel of the object while having everything disabled. I didnt want to use an image at all because it would be stretched, shrank, clicked, etc and wanted to maintain how the editor would look. I had an alternate option i COULD do but not only it would be ineffecient, but have holes to open up for injection.
Looking through the API for that i didnt see which way to accomplish that.
I was thinking to do jquery maybe on the client side to disable, but why do that when you can set the item itself be flagged as disabled and never be entirely sent to the client.
Thoughts? Ideas? How would you go about it? I didnt see methods or attributes that really led to what i was doing.
You can just set enabled="false" on the radEditor declaration in your aspx page:
http://www.telerik.com/help/aspnet-ajax/editor-disabling-radeditor.html
<telerik:RadEditor runat="server" ID="RadEditor1" Enabled="false">
<Content>
<strong>sample content</strong>
</Content>
</telerik:RadEditor>
On the Server Side you can do
RadEditor1.Enabled = false;
In jquery,
try
$("#RadEditor1").prop('disabled', true);

FCKEditor and ASP.NET CSS

I've got an ASP.NET webforms project, and I want the fckeditor to use the stylesheet of the site so that people without HTML knowledge can look at the site and make changes.
Here is my current code:
<fckeditorv2:FCKeditor runat="server" ID="txtPageContent" Height="600" BasePath="~/FCKeditor/" ForceSimpleAmpersand="false" FormatOutput="false" EditorAreaCSS="../App_Themes/Professional/master.css"></fckeditorv2:FCKeditor>
As you can see, I've set the EditorAreaCSS property but it still doesn't put up the styles.
Instead of the ../App_Themes I've tried ~/App_Themes and /App_Themes but nothing.
The stylesheet certainly exists, and I've tried setting this in both the code behind and in the ASPX file.
When looking at the source, I get this in the hidden field that fckeditor makes:
<input type="hidden" id="ctl00_contentMain_txtPageContent___Config" value="ForceSimpleAmpersand=false&EditorAreaCSS=../App_Themes/Professional/main.css&FormatOutput=false&HtmlEncodeOutput=true" /><iframe id="ctl00_contentMain_txtPageContent___Frame" src="/eJs.Web/FCKeditor/editor/fckeditor.html?InstanceName=ctl00_contentMain_txtPageContent&Toolbar=Default" width="100%" height="600px" frameborder="no" scrolling="no">
Any ideas would be most appreciated.
I hope this will help. Probably best would be set it from code behind
EditorAreaCSS = this.ResolveUrl("~/App_Themes/Professional/main.css")
ResolveUrl() method is Page method, actually any System.Web.UI.Control should have it

Refresh an iframe using ASP/VB?

I have an iframe, looks like this:
< iframe id="PDFLetter" src="http://127.0.0.1/letterwriterasp/pdfs/test.pdf" width="60%" height="500" runat="server" scrolling="auto" >< /iframe>
Problem is, that pdf file is regenerated. So I need to refresh the iframe to reflect the changes to the user. I tried this:
PDFLetter.Attributes("src") = ""
PDFLetter.Attributes("src") = "http://127.0.0.1/letterwriterasp/pdfs/test.pdf"
But to no avail. It doesn't refresh the pdf in the iframe.
Not sure what can be done here. Any ideas?
Thanks,
Jason
Are you doing this on a postback and entering the code in the PageLoad event? If so it should work (for complete control over html you can laways just write to a Literal control although this is much heavier).
Try adding a random number at the end of the pdf name using ?randomnumber so that it does not use a cached version of the pdf file.

How to show Image with http url in asp.net

In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
Now I want to display it on my datalist. But it is not showing any image. It is might be the case because it is expecting the Image URL to be ~/Folder/abc.jpg
Then how to show the image on the asp.net page when I have image URL, which control I need to use and how?
Do you see little red X instead of an image?
If so, right click it --> Properties (IE) to see the URL it's referring to.
Might give us hint on what's going on. :)
If you are getting the image from the database in for the form xzy.com/1009/image1.jpg but want to add the http:// then your code should be
<asp:Image ID="imgmain" runat="server" ImageUrl='<%#String.Format("http://{0}", Eval("Image"))%>' Width="80" Height="80" />

Resources