Blazor Server App routing 404 - File or directory not found - asp.net-core

I have created a blazor server app. it is working on my machine when it is running using localhost. There is a folder configured in the IIS for this project.
I have published the project to a folder and then copied/paste the dll files to the configured folder in the IIS.
The main page (index page) is running perfect , but when I tried to click to move to another page, I got the error "404 - File or directory not found".
Note :- when I browse the project from the IIS , the name of the project has been replaced from localhost to abcdef.com.
Could anyone help me to correct the routing problem ?

I think its related to your page definition of your Balzor components. "/" means the root folder of your website. If you want to add this application to your existing website, you probably upload it in a new folder in your host. For example https yourwebsite/app. In this scenario your new application is not root of your website anymore. So your page address should be something like this:
#page "/app/address".

Related

Hosting blazor wasm asp.net core hosted app in kestrel

I am having troubles hosting the blazor wasm asp.net core hosted application.. The solution has 3 projects: Client, Shared, and Server.
when I run the command dotnet publish --configuration Release it publishes the libraries to their respective folders in solution like this:
WebWorkbench3\Client\bin\Release\net5.0\publish
WebWorkbench3\Server\bin\Release\net5.0\publish
...
I would assume that since the server project is referencing a client - then my steps to host the application are following:
Open WebWorkbench3\Server\bin\Release\net5.0\publish in powershell
Run command dotnet .\WebWorkbench3.Server.dll
Navigate to: https://localhost:5001/
Result:
Expected: client page opened
Actual: page is stuck at "Loading.." string. In the console we see that there was an error about _framework/blazor.webassembly.js not being loaded.
If we were to check the wwwroot folder contents in the server app we will see the following:
So this explains why the error is shown. However my question at this point - should the publishing process/configuration in project take care of copying client's wwwroot contents into the the server's app output directory? If we start a debugging session in the VisualStudio, then we use the server as the startup point, so the project should have some idea where to look up the blazor.webassembly.js file at..
So why doesn't the same process occurs during the publishing?
Note: I was able to fix the issue by manually copying the client's wwwroot directory and by placing the contents into the server's wwwroot directory... But I don't think that is is how serving is supposed to work?
EDIT: I have just tried to set-up the client blazor application in IIS. And it works. Kind of. The page is opened. But then when it tries to make a REST GET request to the server - it uses the same hostname:port combination. So if my app is hosted on mysite.local:50001 then the request to API will look like mysite.local:50001/data/loadall where data is the controller name and loadall is the action name.. So basically the client uses the same base address as the server.. The problem, is that I cannot start the server on the same port as the client! In attempt in doing so - you will see following output:
So basically I have the same question as before - how to host the wasm application that is split between client and the server? I am pretty sure that I can make it work by forcing the client to use the non-standard server port and serving the server part on that port.. However, I believe there should be a reason why current configuration (default configuration in the blazor wasm template) is configured in this way so it should be possible to run the project somehow without any additional changes at all..
Well this will be a self-answer.. Instead of publishing (dotnet publish --configuration Release) the application on solution level - do the publishing on project level..
before ..\repos\WebWorkbench3\WebWorkbench3
after ..\repos\WebWorkbench3\WebWorkbench3\Server
In 1 case the compiler does not copy the _framework folder (and possibly some other files) into the wwwroot.. Once you have published the Server correctly you can access the app by serving it with dotnet .\WebWorkbench3.Server.dll command.
Having the samie issue as explained above:
Before:
The solution file
had the same name
was in the same folder
as the server project
Resolved
I moved the solution to the project root (one level up).
Now, dotnet publish within the server project produced the __framework folder + content as expected.

How to enforce Azure Virtual Application base path?

I have an Azure App Service which has two virtual applications (Asp.Net Core Blazor apps, if it's important) hosted within it. The virtual application URLS are something along the lines of
https://site.azurewebsites.net/site1
https://site.azurewebsites.net/site2
I have noticed that some of the internal routing seems to not be taking the virtual application path into account. For example, a link that takes the site to the "/" route navigates to https://site.azurewebsites.net instead of the appropriate "base" virtual application path. Is there some way of either handling this in my application or within the azure configuration?
Thank you for any assistance!
Adding to Hassan's suggestions, on App Service, Each app has the default root path (/) mapped to D:\home\site\wwwroot, where your code is deployed by default. If your app root is in a different folder, or if your repository has more than one application ( as in your case), you can edit or add virtual applications and directories here.
To configure virtual applications and directories, specify each virtual directory and its corresponding physical path relative to the website root (D:\home). Optionally, you can select the Application checkbox to mark a virtual directory as an application.
From Azure Portal > Navigate to your WebApp -> Settings (Configuration)-> Path Mapping> Virtual applications and directories.
if you browse via console Kudu console in your app service blade you will notice a directory, under wwwroot is the root directory which by default your application routes to. This you can change from App Settings blade option. Also in this directory you will find you can create other folders aka virtual applications which will work the way you want it to.

IIS is not allowing to access a javascript file

i have a web application. while running in my system integration environment, i get an issue while accessing my javascript file or an image file in my particular folder.
When i tried putting the complete URL in the browser, it gave me a following exception -
HTTP Error 404.2 Not Found
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the webserver.
I googled this exception and found that i need to allow ASP.NET 4.0, 2.0, etc in the IIS's ISAPI & CGi Restrictions.. however, they were already in allow mode.
What next should i lookup?
OK,, i got the answer
the HTTP Handler in the applicatin's web.config file was trying to execute via a aspnet_isapi.dll located in Framework64 folder of .NET Framework.. the target machine however is a 32 bit and i dont have this Framework64 folder on it..
i changed the path of the executable to point to the 32 bit's folder and it wrked :)

Website not loading on LAMP but test page displays

I have set up my LAMP server on Ubuntu 14.04. I have created a virtual machine to host a website. The directory structure is:
var/www/DS/public_html
I have set up my configuration files so that the server responds to the url:
http://ds.local
I have created test pages inside public_html called index.html and index.php. I have modified the configurations so that index.php is the default page that gets served. In the test page named index.php, the only line of code is:
<?php phpinfo(); ?>
when I go to http://ds.local frrom my browser, the page gets served up and I can see all my php configurations. So. everything good till now.
I have a website which I had developed on WAMP. Now, when I try transferring the files of this website into public_html and try reloading the browser, nothing happens. I have looked at the developer tools window, and I am certain that no page loads.
I have ensured that I have copied all the files and folders making up the website, including all the folders containing js and css. I have also ensured that there exists a file called index.php
Where am I going wrong?
I have a website which I had developed on WAMP
Are you sure that all files are referenced by correct case?
Windows file systems are by default case-insensitive.
http://localhost/DS and http://localhost/ds
are same on windows but not on linux/unix.

Virtual Directory to navigate to http://localhost/MyWebsite instead of http://localhost:8080

I have deployed an ASP.NET MVC 4 application to a new site I have created in IIS 7.5, which I have bound to port 8080. I can reach it by navigating to http://localhost:8080, but I want to reach it via http://localhost/MyWebsite.
I have added a Virtual Directory under my website, which points to "C:\inetput\wwwroot\MyWebsite\". However, when I navigate to http://localhost/MyWebsite, I am presented with a configuration error:
"It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This
error can be caused by a virtual directory not being configured as an
application in IIS."
Here is what my IIS hierarchy looks like (this is a demo since I have no internet access on the server I am working on).
I have two questions:
Why am I getting this error?
Is this the best way to go about achieving what I want? It seems messy to have the list of files and folders underneath the website and then again underneath the Virtual Directory. If there is better practice then please tell!
Virtual Directories cannot execute scripts, reason why you are getting that error. You need to make your MyWebsite folder an Application. Also, you don't necessarily have to create a separate website for your website, you can use the Default Web Site and create an application MyWebsite in there (it might be less confusing maybe?).