Custom Error Page in Shiny - r

When visiting a page pointing to shiny app, such as myshinyapp.com/NoSuchPage.html, shiny will return "Not Found" information page. I suppose it is error 404 page.
How can I replace this "Not Found" page with my own page?
Thanks.

From section 2.10 of the manual:
Shiny Server can utilize custom templates when generating static pages such as directory indexes and error pages. This feature is controlled using the template_dir directive and can be applied globally, or to a particular server or location.
To utilize this feature, you'll need a directory in which you'll store your templates. In this example, we'll assume you're using /etc/shiny-server/templates/. Inside this directory, you'll place the handlebars-enabled HTML templates for your pages.
Shiny Server will attempt to find a specific page to accommodate the current need -- for instance, if it encountered a 404 error, it will first look to see if you provided a specific template for handling 404 errors in the specified directory (error-404.html). If it doesn't find this file, it will go one step backwards to see if you provide a generic error template (error.html). If it can't find a suitable template in your template directory, it will fall back to use the provided templates that come with Shiny Server (and are stored in /opt/shiny-server/templates).
As you may have noticed already, Shiny Server uses a hyphen-delimited hierarchy which progresses from broadest to narrowest. So all error pages start with error. But the file name for a 404 error page would add an additional element (404) following a hyphen: error-404. All files are expected to use the .html extension.

Related

How to access html file inside iframe in production

I am creating a web app where, this app will generate a .html file in public/ directory. And after that i want to show that generated html file on a page using iframe .
I am using NextJS for this task. I have configured next.config.js for rewrites but getting 404 error. I am using Railway for hosting. Since in Vercel we can not access filesystem here.
Instead of generating html dynamically, if I upload that .html file, then i can access that file using iframe in production.
I think we can not access those files which were not available during build process. (this is my guess , maybe wrong)
How can I solve this problem or should I use another framework ?
Thanks
Since I was accessing .html files (i.e <iframe src="path-to-file"></iframe>) which were not available during build process, that's why i was getting 404 error.
So I did the following thing:
suppose I want to do this <iframe src="/pdf/page01.xhtml"></iframe> where file location is in public/pdf/page01.xhtml.
so this src is sending a GET request to localhost:3000/pdf/page01.xhtml.
To manipulate this request I created a pages/api/pdf/[...slug].js. In this file you can use process.cwd() to access the file inside your public dir. You read file content using fs.readFile and send the response res.status(200).send(data) like this.
By doing this I was getting the desired result.
Suggestions are always welcome.

What are valid page names in Next.js? And how does it distinguish between pages and static resources?

I'm new to Next.js and am trying to get my head around client side and server side routing and what files need to be made available to download when Next.js is configured to use server-side rendering.
When I do a production build of a Next.js project, a .next directory is created (details here). When I call next start and then load a page that uses SSR (by defining getServerSideProps()) then I can see in the developer console that the page that I load downloads resources that are prefixed _next (e.g. <script src="/_next/static/chunks/main-3123a443c688934f.js" defer=""></script>).
Can someone confirm whether the .next directory contents (.next/server/**, .next/static/**) are just made available on the server by being renamed to _next?
I tried creating a new page in a file called _next.js as an experiment. The project builds correctly (no errors reported and there are build artifacts created with the same naming convention as the other pages). However, when I try to load that page, I get a 404.
Are there restrictions on what constitutes a validly named page in Next.js? If so, what are they and where is this defined.
How does the Next.js server know what is a static resource that should just be given to the client and what is a page for which Next.js should render an output? Is it simply an algorithm like "if the path starts _next/ then return what is requested, otherwise render?"
How does Next.js know to distinguish between resources that are in the public directory and pages? e.g. if there's a collision between the name of a page and a resource in the public folder, how does the server know what to return to the user?

web.config file not there in the root(/) directory

I was trying to run a .cshtml file but it gave an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /index.cshtml
So I searched for the solution and found that I had to edit the web.config file which is in the root directory(here it is My Site), but there is no file like that there there is only an index.cshtml which I had created.
I searched even the IIS and the IIS Express folders in Programs Files\ but there was no file like that?
If you are using WebMatrix, maybe your mistake was the starting point choice.
If you want to create a new Web Pages site you must start from a template in the Template Gallery of WebMatrix. Pay attention that the Empty Site template differs from the Empty Site option outside the Template Gallery because the first holds the files (binaries, packages and the web.config too) that are needed.
As the server error suggests, .cshtml files are not served, the reason for this is because they are server-side files that make up your application, they are just one piece of a much bigger picture.
If you launched your web application in debug mode and the URL in the browser was something like http://localhost:2932/Views/Home/Index.cshtml, just drop the /Views/Home/Index.cshtml part of the URL.

How do I download an msi file via an asp.net button?

So, I've created my wonderful winforms app that I want to unleash upon the world, and now I am trying to create a simple website to host some basic information and link to the setup file (msi installer file )....
I have a button on the asp.net page and the setup file setupApp.msi in same folder as the asp.net page. I am currently trying the following:
Response.Redirect("http://./SetupApp.msi");
But this best guess at what to do is not working. Is there something wrong with Mime types here? What do I need to put in the click event to allow users to download this file?
The path you are passing in to the method is not valid (there's no server name called ".").
You can pass in a relative path and it should work fine because ASP.NET will resolve the path:
Response.Redirect("SetupApp.msi")
Or if it's not in the same folder, try one of these:
Response.Redirect("../Downloads/SetupApp.msi")
Response.Redirect("~/SomeFolder/SetupApp.msi")
Keep in mind that you don't necessarily have to do the whole redirect at all. Instead of writing code in an ASPX file you could just have a link to your MSI:
Download my app!

asp.net: RewritePath to Default Document not Working as Assumed

I am encountering an unexpected behavior:
The following statement works fine:
Context.RewritePath( "~/Default.aspx" ); // redirect to default doc, explicitly
This gives me a 404 error:
Context.RewritePath( "~/" ); // redirect to default doc, implicitly
Loading document / from a browser without doing any URL rewriting correctly loads the document, so I figure IIS is correctly configured, and that / and /Default.aspx indeed refer to the same document.
I would rather use the latter statement, as there is a possibility that the Default document name will be changed in IIS as time goes on. I'm assuming the solution involves some method to retrieve the Default Document name from IIS, however I've been unable to locate such a method.
So my question is: What is the correct way to specify a default document when rewriting the URL?
Your problem is that IIS handles the path translations for the "default document" before it turns control over to asp.net.
When a browser requests a URL without a file name, IIS will check the list of "default documents" configured for that site. It then looks for physical files in the requested path that match the name of the configured default documents. It then returns the first matching default document that physically exists on the disk.
After this, if the requested file is an asp.net file, it will invoke the asp.net runtime and hand off processing to asp.net.
Your URL re-writing takes place inside the asp.net process. It has no awareness of IIS's settings with regards to default documents and such. When you use a technique like URL re-writing that take place entirely within asp.net, you can't use default documents and such. So always re-write using the page name.

Resources