C# .net Offline page? - c#

So I have here a .NET C# web app that needs one page able to be viewed offline as a user could be off in the middle of 'whoop whoop' with no internet.
The order of events are:
User visits a form online
Store the webpage using HTML5 so they can visit it later offline
When online - the user then can submit the form to the database
I've been looking over HTML5 appcache however it seems to only reference physical .html or .php pages rather than storing pages which have been generated by 'Razor' .cshtml Views.
e.g. domain.com/path/view.
I haven't been able to find any relevant documentation for my problem either.
So is it possible to cache a .NET webapp ofline?

Although I have not tried it, and assuming your app uses ASP.NET MVC, this might help you:
Build an HTML5 Offline Application with Application Cache, Web Storage and ASP.NET MVC
It uses HTML5 Offline Web Application API (or HTML Application Cache). Note the comment on browser support.
The linked article shows a sample application, but I could not see a link to a downloadable source code. But one commenter appears to have recreated the project.

The appcache is what you need. Note that you specify the pages to be cached, but the browser never sees if the page is a static .html or generated via Razor. As long as the path you specify opens the right page, it will be cached.

Related

Storing data per session in asp .net core with angular front end web app

I'll start by mentioning I'm new to angular and I'm new to ASP.NET. I am working on a web app that combines pdf documents into one pdf document. The tool is an angular front end and ASP.NET core back end, and it should support multiple browsers at the same time.
I have got a functioning version of the web app already going, but without the support for multiple browsers. It works as follows:
Submit pdf 1 through the angular app, that posts the pdf to the asp.net backend controller. The backend stores the pdf in a service (singleton service).
Submit pdf 2 through angular app, that posts the pdf to asp.net backend controller which stores pdf in service
Click Combine button in angular app, which posts a request to backend to combine the pdfs it has into 1, and return the newly created pdf to the angular app.
Obviously, the problem here is that I use a singleton service to persist data for the browser: If I submitted pdf1 through one browser, and then loaded up another browser and submit pdf2, and load up another browser and click the combine button, it will combine pdf 1 and 2 - which is obviously not right!
I've been looking into using session data to store the individual pdfs, but ran into a problem in that using session data in SPA applications is not advisable, and with web api is code smell. So I'm wondering what the correct way to tackle this problem is so I can go away and read up on it! How do I go about storing data per user / per browser temporarily in angular web app with asp.net backend...
I would move away from the singleton having any awareness of session/users/documents/etc and just do activities; it should be pretty stateless.
I am guessing you are persisting them in memory, which is what you mean by in the service, and that can also get tricky. Scaling could become an issue very quickly.
Perhaps there is a technical and UI solution to this? Could you persist the PDFs in a datastore, and then choose which to combine from those in the database in a separate view or page? This would be the cleanest from a data perspective.
However, if you are deadset on the same view and that view/session only being aware of what has been uploaded in that session, you would need to use some sort of identifier as J.Salas mentioned. I would still vote for moving away from storing the documents in memory, but the solution here wouldn't care either way. You can prepend the pdf identifier stored with the session ID and you know which is attached to which.

C# WPF, and data exchange with the browser

I've a C# WPF application developed in VS 2015, and I want the browser to read some data from it. Just a short string. I can save it in a text file, or in a variable but it should be visible to the browser (using JS I suppose). For instance using file:/// doesn't work if the original page is hosted online - as in my case (different source conflict). This should work in Opera and FFox, but looking at their extensions, it seems you can only develop with front-end technologies, which are not enough in my case since I use WPF to look into Win OS, and then I need to share the result with the browser.
I suspect it's possible, and no , it's not to write a malicious piece of code. For instance I can read the details of the graphic card for diagnostic purposes.
Please help, many thanks.
Browsers run in a security sandbox which is intended to stop them reading or writing files to the file system.
You could write to the user's appdata. There are various javascript frameworks which persist data to there so they can provide offline or static data.
I don't think that is a good plan though.
I suggest your first candidate would be a cookie.
Quick google on how to do that, I find:
How to create cookie in c#.net windows application?
From a web page you can use the content of a cookie dynamically. So you could change what you see in the web page after it's up and running from some process in your wpf app and do a counter or whatever.
I've not used this with windows apps and a browser but I have with a web app and Silverlight. I'm afraid I don't have that code to hand though.

Aspx Support PWA or Not

Are there any way to do a project using pwa concept in ASPX page? I am using HTML with PWA, it was working fine but I moved into the ASP .NET. It doesn't work anymore and the JSON file is not loaded.
You will maybe found this SO post useful.
After testing, i was successful at implementing the functionality by
adding the serviceworker and manifest to a ASP.NET MVC application.
Since the view (HTML) gets rendered in the backend, it's only possible
to cache an static version of your web application. So preferable you
should use angular etc to generate your HTML.
A progressive web app works on IIS and apache web server.
progressive web app is a general concept. It has nothing to do with your web server. Please give more details about your code architecture etc
you can also use swtoolbox plugin for handing client side caching
mybe your problem is client-side caching. however PWA concepts are as follows, neither of them has nothing to do with web server type
Progressive - Works for every user regardless of their browser
Responsive - The app works on any form factor whether it's desktop, mobile, or tablet.
Connectivity-independent - Allows the user to use the web app even if it's offline.
Native Look-and-feel - Acts and feels like a native application, but is strictly web-based.
Safe - Always served up to the client through HTTPS.
Discoverable - Even though it's an "application," it can be indexed into a search engine.
Re-engageable - Allows re-engagement through features like push notifications.
Zero-Deploy hassle - Allows users to add the web app onto their home screen without the issues with app stores.
Link-friendly - Allows you to reshare using a Url.
Yes finally I able to accomplish this. PWA now works not only on ASP.NET webform but On any framework.
https://github.com/cpbenipal/PWA_Aspx

wkhtmltopdf not working on intranet sites using C# MVC3

I'm having issues with converting my Intranet Page to PDF file. I used 2 solutions which actually works, however with some issues.
Solution 1:
I used wkhtmltopdf.exe tool. I was able to make it work on my local machine.
However, when I deployed it to our Server, it stopped working until I notice that it's not working with intranet sites. When I tried extranet sites, it's working.
Solution 2:
I took an alternative solution by getting the HTML of that site, and let the wkhtmltopdf.exe tool to make it PDF which also works, however, the data on my page that I'm trying to convert to PDF is database driven. So all information including images was not supplied when it was converted to PDF.
Please help if there's a way to make the wkhtmltopdf.exe tool work in Intranet Sites(solution 1) or
how I can retrieve the whole page including data and images when converting it to PDF(solution 2)
Thank you very much!
it stopped working until I notice that it's not working with intranet sites.
That is not an exhaustive problem report. I have done it by rendering a view to a string and then converting that string to a pdf using wkhtmltopdf.
Rendering the view to a string: Render a view as a string
i did not include wkhtmltopdf direct, rather I used the tuespechkin nuget package: https://github.com/tuespetre/TuesPechkin
I would say to look at the permissions available. Intranet sites normally have different permission levels than a public facing site. It could be that the public facing sites have permissions that have been applied to the .exe such as the IIS_IUSR account to enable it to work with anonymous guest accounts, but lack the permissions needed in an intranet which often uses the domain user account of the logged in user to authenticate resources.
For whtmltopdf software to generate pdf on your intranet server, you need to have 2 files msvcp120.dll & msvrp120.dll in the same folder as wkhtmltopdf.exe file to running from server side. Hope this helps.

Uploading files using AJAX and JQuery in an ASP.NET application

I have several input type files in my asp.net Web Form.
How can I upload files to Server using Jquery, AJAX and C#?
The uploaders are generated programmatically so I cannot upload the files using code behind.
Also, many files must be uploaded at once.
Is there anyway I read the file via Jquery, send it via AJAX to server and upload it there?
THanks
Have a look at Fine Uploader. It does not use flash or java. In fact, it does not have any required dependencies. An optional jQuery plug-in is provided, if you use jQuery though.
Support: IE10-7, Chrome, Firefox, Safari (OS X), as well as Android tablets and phones, along with IOS6 tablets and phones (iPhone & iPad). The Microsoft Surface tablet has also been tested.
There are many features to choose from. Have a look at the demos and, more importantly, the docs and associated blog posts for more details.
Furthermore, there are many server-side examples that may be helpful during integration of this library into your app. See the server directory in the Github project. ASP.NET is one of the many examples.

Categories

Resources