Making MVC Controllers in Umbraco, But Can't build the website - asp.net-mvc

I am looking for making some MVC Controller and Models so add my desired functionality to my website, but How can I add a controller while the project can't even build, because there are lots of compilation errors in umbraco internal pages (e.g. in Umbraco/ and UmbracoClient/ folders).
How would I overcome these problems and make my own controllers - models? don't they need a compilation?

Without seeing your compilation errors I can't be sure, but unless your version of Umbraco is seriously corrupt the most likely cause is because there is a problem with references - either to packages in the packages folder (which Umbraco 6.x.x builds create) or to another folder (references?) that someone may have added if you are using mvc bridge and Umbraco 4.x.x.
Assuming this is a 6.x.x build then are the errors connected with missing assemblies? Are the permissions on the folders (like packages) in your solution allowing access? Is the packages folder missing?
You could create a new blank Umbraco instance and migrate your work so far if your Umbraco install is corrupt.

Related

Controllers folder missing Umbraco 8

I installed Umbraco 8.4 as per the instructions found at https://our.umbraco.com/documentation/Getting-Started/Setup/Install/install-umbraco-with-nuget
Once done within Visual Studio 2017 i tried to created a new Controller and the folder (Controllers) was missing.
I'm not sure if i've missed something but i didnt want to create the folder manually in case it introduces new problems later down the line.
I thought to recreate the project but instead of selecting Empty as the project to use MVC but after reading through a few threads it seems the correct way is to select an empty project.
Under the bin directory i do see System.Web.Mvc.dll
Am i missing something?
You should definitely not use the MVC project template when creating a new project - that will add all sorts of dependencies that will likely conflict with what comes with the Umbraco NuGet package.
Go with the "Empty" template and then add in the NuGet and it will give you the dependencies you need for Umbraco to run. If you need to add in other stuff from MVC afterwards, you can add these in a version that aligns with what the Umbraco package has added.
In regards to the Controllers folder - it really doesn't matter where this folder lives or what it is called. Controllers are registered by other means. You are totally fine to create this folder manually and call it whatever you prefer.
I think most people actually prefer to keep Controllers in a completely separate project in the VS solution. Then reference that project by your main project to ensure the compiled DLL is included in your web project - and thereby your controllers can be used by the Umbraco website itself. By doing this, you get a clean separation of your .cs source files so you won't accidentally be deploying those when you deploy your site. To do this you would of course require to add UmbracoCms.Core NuGet package to your other project in order to use Umbraco functionality.
Keep in mind if you are adding plain MVC controllers (not inheriting from the Umbraco base controllers - and therefore not getting automatically registered) you will need to manually register these controllers in the route table in order to access them.
This is no different from what you would do in a normal ASP.NET MVC project, but since this isn't added by default in an Umbraco project - you need to do it yourself.
See this answer for instructions on how to do it: https://stackoverflow.com/a/56972929/336105

How do I fully customise the default ASP .Net Core Identity pages?

I'm currently trying to learn and understand all the new Identity bits and pieces with .Net Core 2.1/MVC. Previously, I have used MVC3 MVC Identity and it was straight forward - it automatically created the Model, View and Controllers and I could easily edit everything and anything.
With .Net Core, it seems to automatically inherit everything from the framework and I just don't easily understand how to override.
I've followed the guides located here, and have managed to scaffold all the pages (e.g. create user, reset password, login), however, this does not create any of the models or controllers.
Because of this, I now have a project with all the pages, but, it fails to build with all the models missing:
CS0246 The type or namespace name 'ChangePasswordModel' could not be found (are you missing a using directive or an assembly reference?
I feel like I am missing something obvious and I can't believe that I am struggling so much on something that ~10 years ago was simple.
How can I create/import the missing Controllers and models?
Identity comes with a default UI composed of Razor Pages and static files housed in a Razor Class Library. It's added by default when you either use AddDefaultIdentity to enable Identity in your project or explicitly call AddDefaultUI on any of the other Identity bootstrapping extensions methods (AddIdentity/AddIdentityCore).
Views and static files in Razor Class Libraries are embedded resources, and as such are treated as if they physically existed directly in the apps that reference them. However, anything that actually does physically exist in your app will be used before any embedded resources. As such, you can override anything coming from an RCL, simply by creating the same file in the same location as it exists in the RCL in your app. The Identity scaffold simply copies over the selected Razor Pages into your project such that they will override in this way.
Since Razor Pages are used for the default UI, there's no controllers or separate model classes. The models used for the views are established in the Razor Page codebehinds, so for each page you scaffold in, you should have both Page.cshtml and Page.cshtml.cs files added.
If your build is failing after doing the scaffold, the build is not seeing the *.cshtml.cs files (codebehinds). Verify that they do exist in your project's file structure. If they don't, there's some fundamental problem with the scaffold in your instance of Visual Studio, which will likely require reinstalling or at least repairing Visual Studio.
Assuming they are there, then there's something stuck in the build process. Occasionally files do get locked and Visual Studio will complain that it's missing references, when in fact it's simply missing the very assemblies those come from. In such cases, you can navigate into your project directly and remove the bin and obj directories completely. Then, come back into Visual Studio and do a rebuild. If you have more than one project, you should rebuild your entire solution, as it could be a project reference that's actually failing to build.

ASP MVC nuget packages are not added to the correct folders

I've added two well known projects to an ASP MVC application and it looks like the packages don't install under /Scripts and /Content as expected (CSS and JS are bundled together).
Am I missing something? Do package authors assume that people will move content to the correct folders, or does no one use the default ASP MVC template folders?
E.g.
Am I missing something?
Nope.
Do package authors assume that people will move content to the correct folders, or does no one use the default ASP MVC template folders?
Pretty much both.
There is no guarantee that packages will properly conform to the default ASP.NET MVC template.
The authors have probably done it because
As a standalone project, it makes logical sense to put them in such a folder structure.
The project may be trying to be generic across many platforms. In this case it doesn't fit with MVC too well.

MVC 3 Views not deployed

I have been working on a small project on recent delived ASP.NET MVC 3 RC. The issue is that when I try to deploy my website via File System, certain views of my website are not deployed. The site gives me error when i copy same deployed site to my hosting. When I manually copy views to hosting, it works ok.
Now this thing is not breaking anything as such, just want to know that if I am missing something while deploying my site. I am not sure why few views are deployed and why not others. Seems very random to me.
Thanks,
If you created the app before RC (aka using our Beta) we had a bug in which we didn't mark the views as "Content". New apps using the RC have this bug fixed, but if you open an existing project, it doesn't automatically fix up the existing files.
To fix them, select the file and in the properties pane, set the Build Output to "Content".

Install ASP.Net MVC without administrator rights?

Unfortunately, my company's IT policy doesn't allow me admin privileges to my own machine. However, I want to start working ASP.Net MVC; but the installer won't install the framework w/o admin rights. Is there anyway I can install MVC manually; like copying relevant DLLs somewhere, etc. Any constructive advice is greatly appreciated.
You can download & compile ASP.NET MVC yourself - and either include it as a referenced project, or just grab the resulting binaries and add them to your project like any other DLL.
Look for the link to MVCBetaSource.zip on this page - it's a pretty straightforward build using Visual Studio, and (if I recall correctly) includes the few binaries (System.Web.Abstractions and System.Web.Routing) that aren't part of the MVC source itself.
As of preview 3 or 4, ASP.Net MVC became binnable. What I've done in my solutions is have a 'binary references' folder at the root of the solution and make references to those local files in each project that needs them. You should copy:
System.Web.Abstractions.dll
System.Web.Mvc.dll
System.Web.Routing.dll
Once done, refer to these assemblies and things should work just fine. The biggest hurdle you face is extracting them from the MSI.
MVC is bin deployable, so if .Net 3.5 is installed with SP1 you should be good. Just make sure you mvc dll gets put in your bin folder and deploys out. The tricky part is the wildcard in IIS6, IIS7 will do this automatically but for 6 you need to make a rule, good luck.

Resources