Razor Project on with CSHTML files - asp.net

A project kind of landed on my hands and I am having issues with one thing.
I have an already working project that is installed on a local server. I am able to make changes to existing pages, but I just tried creating a new page from copying an existing page and modifying it, but I keep getting an error when I try to open it. This is the error:
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
From my research so far, it looks like there has to be a controller in place to properly map the new pages, but I have not been able to find that within the project. I copied the project and opened it with ms visual on a different machine, same issue, everything opens and works just fine except the new page that I added. While the project is open on ms visual I do not see a folder for controllers either.
I would greatly appreciated if someone can point me on the right direction
Thank you,
Cesar R

With Model/View/Controller, you need a Controller to match with the View.
Let's say you add a new folder and cshtml to your file in the following folder:
~/Views/Test/Test.cshtml
You also need a controller named similarly in the following folder:
~/Controllers/TestController.cs
and inside that controller you need a method that matches the name of the view:
public ActionResult Test()
{
return View();
}
That will make http://[yourwebsiteurl]/Test/Test be an active page.

Related

SurfaceController file edited by Kudu does not change the application content

i have a problem with my application created in umbraco.
I have implemented the application on microsoft azure and I wanted to edit one function in the controller using kudu. I have edited the controller file, but the changes have not been made in the application (as I will go to the site is the state from before editing). I have combined a bit how to get the desired effect, I even deleted the controller file and it is still the same (state from before. Can you write to me how to correctly edit the controller file?

Xamarin Forms can't find my localized string

I'm trying to get a localized string:
Debug.WriteLine(AppResources.Duplicate);
But it gives me a TargetInvocationException. I don't get why, because the autocompletion indicates there are no problems. What could I be doing wrong?
Edit: now even the autocomplete is not able to find AppResources, I get errors even though it was working before.
I've put my AppResources into a new folder called resources, I guess this is not allowed as it's a reserved name for a folder: https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_resources/
I created a new RESX file, copy-pasted the contents to this new file which is not in a folder called resources and it's working again.

Running a copy of a .cshtml file gives a 404

I've created a copy(right-click Copy & Paste) of my Home page in a VS2013 ASP.NET MVC5 project and named it indexL10. When I try to run it, I get the following error:
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /Home/IndexL10
So, I'm guessing there's more to it than copying and pasting. I've tried googling around, but I've not found an answer, or search string that takes me to a page of a user with a similar problem.
Does anyone have any ideas/suggestions? Thanks
*.cshtml files are not like *.aspx files. They're not directly exposed. The URL is translated by the framework into a route. That route points to a particular controller and a particular action in that controller, which is then called by the framework. The action returns an ActionResult, which in MVC is most typically satisfied via a ViewResult. Conventions in the framework come into play to look for a view to render with the same name as the action that was called, but this is not strictly required and can be overridden. Regardless, the view (your *.cshtml file) is rendered by Razor utilizing data provided by the action and returned as a response to the client.

Compiler Error Message: CS0433: The type 'MasterPage' exists in both 'c:\~\App_Web_ogmril5q.DLL' and 'c:\~\App_Web_ogmril5q.DLL'

I have 2 master pages inside one ASP.Net website. It work fine without publishing website. After publishing the website on the web server, one of the master pages works fine, but when I want to access the page that is linked with the second master page it gives me the above error. But the weird thing is that the error paths are in c\ drive of my computer.
When this has happened in the past [rare but I saw it once in production] you need to clear out the contents of your shadow copy folders for your application. These are usually in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files but the error path in your exception details will tell you where.
when copying one web page/user control to create another web page/User Control . After copying one userControl to create another, I neglected to change the partial class name in the .cs of the new userControl and the 'Inherits=' in the .aspx file. Fixing those class names stopped the error from occurring. I suppose the easiest fix to avoid this is to just create new userControls each time using the wizard rather than copying and pasting an existing userControl.
as ex
if we copied the main master page to create another master page, both of them will have the same inherit and that what would create the problem so change the class name and then change the inherit with the new class name or always add new items rather than copy and paste
There are various cs0433 errors that can cause this to occur.
Basically, if you like I did, try and compile the same project with different versions of Visual Studio, they may likely use a different version of the .Net Compilers and libraries.
Therefore, some built assemblies will be duplicated causing differing pointers to the same functionality, but with varying .Net CLR's
What solved it for me, was to recreate the folder from "Virgin Code Files", but with a slightly different name such as "Project1", "Project2", etc..
Then you can rebuild the project from scratch with the correct Visual Studio version, which for me was VS2019 and then "Bob's your uncle :)" No more errors.
Please accept this answer

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!

Resources