Stripping a C# app down to its static web app - c#

We are separating our front end from our back end (C#.NET MVC) so that back-end dev does not block front-end. Instead of a zillion local database updates, I'll be hitting an API.
I've been working in VS up till now, but wish to work in another editor, and be able launch the front-end in a browser directly.
Except that the index page is index.cshtml. There's nothing of note in the index file that requires it to be cshtml, so I could convert it to .html - the only problem is, now launching the app in VS fails because it is only looking for a cshtml file to start, i.e.:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
etc.
My question is: what can I do to modify index.cshtml or the server, so that I can load the app in a browser without having to run it through Visual Studio?
This is the current structure in VS, most of which I hope to dispense with:
App.Data.EntityFramework
App.Data.Sql
App.Domain
App.DomainEntities
App.Presentation.Web
App_Data
App_Start
Areas
Content
CSS
js
apps
dashboard
controllers
views << dashboard files
store << 90% of my files are here
controllers
views
services
etc.
Controllers
ControllersApi
Models
Providers
Results
Views
Home
index.cshtml << actual start page
This is where I go to start the app:
https://localhost:44337/#/dashboard

Related

.Netcore api with ReactJs dynamic URL Pathname

I'm currently in the process of converting project frontend from .netcore web application (razor page) to reactjs, one of the road block we encounter is the dynamic url path that we applied in razor page.
As the application is deployed on IIS under default website, so the url is construct as https://localhost/Project. One of the project requirement is it can to be replicate and deploy many time, so there will be https://localhost/Project{n}. That mean the url path name need to be configurable so the frontend JavaScript will request to the correct api url. What i done was config the pathname in iis application's webconfig and inject it into the razor page, so javascript can refer to the injected pathname variable.
But when come to reactjs, it is a seperate project from backend but they share the same url, and reactjs has no way to get the configurable pathname so it can only stick to whatever set in the public_url/homepage, and it can only be set before project is build. As it is not set dynamically, the frontend point to the right default page but wrong javascript url, so it cant even run the react main chunk js.
Any lead for me to continue on? Or i need to change the way of configurable pathname?
In React you can use standard JS. So in order to get the current path name from your React application, you can do something like:
const pathname = location.pathname
If you need the pathname in many different places in your React project, you can set it as a context. (See this documentation)
Alternatively, if you only need it on the initial load, you can just do a useEffect in your app.js file like:
const {pathname, setPathname} = React.useState();
React.useEffect(()=>{
setPathname(location.pathname);
}, [])

How to fix issue when entering www.sitename.com/ROBOTS.TXT in URL only refreshes the page

I have a site that's about to be taken down in month's time. What I need to do is place a robots.txt to prevent the search engine from indexing it any longer. However, after I placed the file on the root of the solution in the web server, and tried to check if I can access it by typing www.sitename.com/robots.txt, it just refreshes the screen or perhaps just returns to the home page. My application is running in MVC 3.
Things I've already tried:
Added modules runAllManagedModulesForAllRequests="true" in web.config
Used Dynamic Robots.Txt using IHttpHandler and Controller/Action approach (based on this link robots.txt file for different domains of same site)
Played around with MIME Types (removed .txt and back)
I am expecting to see the contents of the robots.txt file same as when I access a css file or js file just by appending the file name in the URL.

HangerFire shows 404 error in Production server while deleting faile jobs

When I am trying to delete the failed jobs in the production server i am getting 404 error but I am able to delete them in my local PC.
URL
https://mywebsite.com/hangfire/jobs/failed/delete
HTTP ERROR 404
URL
https://localhost:59141/hangfire/jobs/failed/delete
HTTP 200
Can anyone let me know why this is happening on the production server only.
There is only one server behind this url..
Thanks in Advanceā€¦
The issue actually I am facing was - I deployed the hangfire application inside the sharepoint website in IIS.
The path deleting the job was something like this on button click
http://SharePointWebsite/MyAapplicationWebSite/hangfire/jobs/failed/delete
This is the path that is getting generated by the hangfire code internally(I added the hangfire assembly reference to my project). My Share Point application due to some configuration issues is not accepting this huge path. So i changed the path to
http://SharePointWebsite/MyAapplicationWebSite/hangfire/jobs/faileddelete
(I removed one "/" in the path) which worked for me.
How to change automatic generated path :
Take the HangFire Code from GitHub which is opensource now
In the Dashboard Pages you will find FailedJobsPage.cshtml. Update this page contents with the short url that you want.
But this cshtml will not be rendered until you run the custom tool - "razor generator tool"(VS Extension) for this cshtml page which generates cs file
You can see these cs files already present in the GitHub Code (expand the cshtml page you will find the cs file)
After finishing the above steps make sure the same path is configured in the DashboardRoutes.cs file as well.
=========================
"ExtensionlessUrlHandler-Integrated-4.0" in "handlers" section
of SharePoint Application web Config is causing the actual issue

Adding Other Projects(Blog Engine) inside an existing MVC5 Azure WebApp

I am trying to add BlogEngine.NET(web) to my existing MVC5 project (which is running as an azure website) partly based on these instructions. I have downloaded/extracted the entire web project folder and included it as a folder to my existing MVC Project.
My controller has the below code
public ActionResult Blog()
{
var path = Server.MapPath("~/BlogEngine/default");
return View(path);
}
But, I receive the error:
....BlogEngine\default' or its master was not found or no view engine
supports the searched locations.
by reading this, I understand why this error occurs. I just want some pointers on how to add the Blog engine to my existing project.
EDIT:
this is exactly what I want to achieve, but azure is not helping(the whole point of me choosing to use azure websites instead of AzureVMs is to shy away from the responsibility of keeping that VM up and running), so looking at the other options at hand, like tweaking my MVC.
goto manage.windowsazure.com
select the webapp
Navigate to the Configuration Tab
Scroll Down to Virtual Applications and Directories
Add the Path of the Directory there and Select the Application checkbox.
Hit Save.

Why isn't my Route.Ignore working on this static file in my ASP.NET MVC application?

Background
I have a PDF file located (under my Project) in an Assets > Documents folder:
When my application gets deployed, it gets deployed to a particular folder on the domain. For example, http://www.domain.com/MyAppFolder. I want to be able to access this PDF file by linking to http://www.domain.com/MyAppFolder/Assets/Documents/EZTrac_UserGuide_NewSys.pdf
Problem
I can't seem to get the routing correct for this, as it keeps trying to route this request to a controller. Here is the modification I made to the routing:
routes.IgnoreRoute("MyAppFolder/Assets/Documents/EZTrac_UserGuide_NewSys.pdf");
But this is the result that I get:
The IControllerFactory
'EZTrac.DependencyResolution.ControllerFactory'
did not return a controller for a
controller named 'Assets'.
Try removing the MyAppFolder from your routes.
routes.IgnoreRoute("Assets/Documents/EZTrac_UserGuide_NewSys.pdf");

Categories