How HTML5 offline cache works with ASP.NET? - asp.net

There are MasterPage.master in my ASP.NET application
My manifest file dose not work:
CACHE
MANIFEST CACHE:
MasterPage.master
Please, tell how should I correctly write MasterPage in my manifest file?

You shouldn't try and cache your Masterpage. If you want to cache any pages that the Master Page uses, instead add the manifest attribute to the HTML tag on your Master Page. That way the HTML page will be cached.
If you need more information on this, I have written an article about MVC and the Application Cache - it should give you a pretty good idea of what you are trying to achieve.
http://deanhume.com/Home/BlogPost/mvc-and-the-html5-application-cache/59
Similarly, try http://diveintohtml5.ep.io/offline.html

Related

Why can't we use *.cshtml files as custom error pages now that (v4.7) we have "Razor Web Pages"?

B"H
Trying to revamp my global error handling, and running into the mess that is ASP.net error handlers.
I would really like to consolidate my solution as much as possible. So if possible I'd like to use the same pages to display from httpErrors and customErrors. I'd also like to use the appropriate Layout pages if possible. But it seems that if I want to use some kind of dynamic page as a custom error page that it needs to be *.aspx. Why is that? Especially now that we have Razor Web Pages?
PS. This is for an MVC (.net v4.7 ie not asp core) Site
If you are using the .cshtml file as a Razor Web Page, then can't you give the URL of the file, excluding the .cshtml? As per the table here: https://learn.microsoft.com/en-us/aspnet/core/mvc/razor-pages/?tabs=visual-studio
A standalone .cshtml file is will normally depend on a Code behind file (if using Razor Web Pages) or a MVC Controller Action to provide it with its data. I guess this is why you are not allowed to redirect directly to one.

add new page to existing website without modifying the rest of the website

i have to add one page to an existing asp.net webforms website.
this will be added at runtime and i'm not allowed to redeploy the entire webapplication / website.
is the (recommended or only) solution to move the code behind code to the aspx file, or do i have other options?
i can't put code in the dll's, and dynamicly runned .cs files are only in the case of a website and not in the case of a webapplication, am i right?
and putting the code from my code behind in de aspx file will always work?
actually as long as their page link to yours via URL you web page doesn't necessary have to be in the same project, unless you're trying to reuse something.
Else technically your project is fine as a standalone and they can just link to yours.
Unless you're worried about the URL then you would have to either use an iframe or some other URL rewrite.
Just for reference: One solution would be to use a dynamic proxy and intercept and extend the existing webapp. Though this approach might be a little too involved for what you're trying to achieve.
LinFu
Castle

404 Object Not Found for Javascript files

I have a .Net 1.1 webapp.
I have a usercontrol (.ascx) that has links to 3 JS files in
script tags.
When I run the app and load a page with the usercontrol
all is fine and Firebug shows the js files listed.
But when I load another page that loads the usercontrol in a .aspx
in a new browser window Firebug reports 404 object not found
for the 3 JS files.
What could cause this??
Malcolm
You other .aspx page is in a different folder? Possible at a different level in the folder hierarchy? You need to adjust you JS file paths so that they are absolute paths.
You probably have the other page in a different location in the folder hierarchy. Perhaps reference you JS with a server side tag with a ~ in it.
So try changing your JS path to something like this:
<script type="text/javascript" src='<%=ResolveUrl("~/someFolder/functions.js")%>'></script>
Use a tool like Microsoft Fiddler to help you understand the issue.
You could try using a basepath in you pages. In that case each url/image/css/js reference in your website will be relative to the basepath. Using a basepath in your site will prevent big issues when moving files into/from folders.
I usually place the base tag into the master page.
<base href="<%=MyWebsite.Library.Configuration.BasePath%>" />
As you can see the basepath is requested from my configuration, but you can also use .NET code to dertermine the basepath.
Using this constructions saves me a lot of issues when developing my pages. Only problem is that Visual Studio does not completely known how to handle this which causes some warnings about incorrect CssClasses or links.

how to cache a control, js files and css files in .net?

I have a master page, inside that I have a menu controls and other css, JS files.
Whenever I refresh the page from client, everything is coming from the server.
Now I want to cache those controls and those files as per session.
Is there any setting or programmatic settings there to do it?
You should read up on ASP.Net Caching - there are lots of flexible ways to cache your pages.
However in your case, it sounds like you should just be able to add the OutputCache directive to the top of your page:
<%# OutputCache Duration="60" VaryByParam="None"%>
Static CSS and JS files should be cached automatically by the browser. If you've embedded them as webresources then the caching directives will help you cache them as well.
There's no problem with JS and other items cached on client.
But yes, there's a concern on dynamic controls as they are not simply compiled and depend on request. And here's an article in Smöråkning blog on how to cache them.

Add web part to sharepoint page in aspx markup

I have an aspx page that get copied in the layouts directory of a Project Server instalation. The aspx is a web part page that has a web part zone. How can I add a web part in the markup of the page, within the web part zone?
You can use the SPLimitedWebPart manager to add an instance of a web part at runtime. I do this on our MySites to control adding, deleting and moving web parts that the organization requires. You can put the code in the aspx page.
SPFile thePage = currentWeb.RootFolder.Files["default.aspx"]
using (Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager spLimitedWPManager = thePage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
Assembly assembly = Assembly.Load("WebPartAssemblyName");
WebPart webPart = (WebPart)assembly.CreateInstance("WebPartClassName");
spLimitedWPManager.AddWebPart(webPart, ZoneId, ZoneIndex);
}
You may need to do something different to gain access to the Web Part Manager for your layouts page. After this you need to redirect back to the page to display the changes. You'll also want to store a bit value to ensure that you do not perform the action on each subsequent visit.
If you only need to do this once then I might recommend PowerShell instead.
Otherwise you can add the web part directly in MarkUp by registering the tag:
<%# Register TagPrefix="ABC" Namespace="Namespace" Assembly="Assembly" %>
and directly adding the web part,
<ABC:ClassName ID="ControlID" FrameType="None" runat="server" __WebPartId="YouWebPartGUID" WebPart="true" />
but we didn't do it inside of a web zone because we did not want to allow it to be removed so I do not know if it works in that scenario. This is easiest but doesn't allow for any customization and SharePoint doesn't really "know" about the web part.
You cannot have customizable Web Part pages in the layouts directory! This is only supported on Web Part pages stored in a document library or other folder in an SPWeb, i.e. ASPX files that you can get an SPFile reference to. Web Parts on ASPX pages in the layouts directory must be added as Web controls in the ASPX source.

Resources