Maintaining .NET web application - asp.net-mvc

I am considering using .NET MVC for my next web app but one of the requirements is that there should be minimum work involved from the clients side (who will be maintaining the site).
They are used to simple HTML sites where all they have to do in order to make a minor change is to modify an html in notepad and upload it.
What parts of an .NET web app needs to be compiled? Is it only the .cs parts of it? Can all the rest be updated freely by modifying files with e.g. notepad?
Also, in an MVC environment, is more of the view related code in compiled files?
How is this kind of maintenance usually done in such cases where the client will take over the site on delivery (and are not interested in needing VS installed and needing to compile!)?

If you really need a web application, then in order to make changes to the 'application' part, they're going to need to be able to recompile.
If they're going to make visual changes, then your best bet is to provide a method for them to edit the HTML of the site. You can make changes to the views (.aspx files) in ASP.NET MVC without having to recompile. If you make changes to your controllers or your Model, then you'll have to recompile.

If this is a major requirement for your client, you can build the site using ASP.Net Web Forms instead of ASP.NET MVC in which case changes to the .cs files will be compiled on the fly when the page is first accessed. Note that this only applies to the .cs files in your Web Forms project. Any .cs files in referenced assemblies will need to be pre-compiled.
That said, I suspect your client is primarily interested in modifying the look/feel/content of a page, so they would probably be satisfied modifying the .aspx files in either a Web Forms or MVC app.
If they have the budget for it, sounds like the best solution is to build a Content Management System, so they don't have to edit files ever again.

Related

Secure ASP.NET Core 6 application back-end code

Is it possible to generate a DLL only from the *.cs files of the project and then remove them and deliver the DLL + rest of the files including the .cshtml files (views) for the client to have autonomy to edit the front? What kind of changes would I need to make to the project, would I need to keep 1 separate full version to be able to generate this DLL and a second project where I would have the DLL + views .cshtml? Do I need to reference this DLL somewhere? Would it be in the *.csproj file?
I recently decided to study ASP.NET Core 6 and ended up creating a very simple system that has several functions such as login, logout, user registration, customer registration, company registration, product registration, all of this is working perfectly, I used the scaffold of aspnet code generator + Entity Framework to generate Create, Delete, Details, Edit, Index and Migrations pages from Models (code first), I tested it with Sqlite initially and then with SqlServer, the system is OK, I can compile it in debug and release/publish, I can put it in production and send it to the client and it runs there without problems, this would be the default scenario where I would sell the solution without it having access to any source code (I won't go into details like reverse engineering , security, protection, etc..., as it is not the purpose of this question), what I need is for me to be able to edit the project for him so that he can edit only the *.cshtml files by modifying the i information from the front as I see fit and generate a new executable for the project, when he needs changes to the backend I would do it for him and charge for upgrades or not charge depending on the type of change.
It sounds like you are looking to deploy your application with Razor Runtime Compilation Enabled.
If you enable this, the .cshtml files that are deployed would be compiled at runtime, meaning that you could manipulate them on the fly without a visual studio recompile.
This is not enabled by default, so you will need to do a few things. First you will need to install the NuGet package for this
Install-Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
Then you will need to add a call to AddRazorRuntimeCompilation() in your builder when you add either MVC or Razor Pages to your project.
For Razor Pages it would be similar to the following
builder.Services.AddRazorPages()
.AddRazorRuntimeCompilation();
You cannot do this if you are using Blazor

Using Razor Templates Stored in Razor Class Library 3.0 (RCL) Without AspNetCore Web Application

I am using Razor templates (cshtml) to build HTML for use in emails. While I can get this all to work and I can send email from a ASPNetCore 3.0 web application I want to actually send email from another process which is NOT a web application. Ideally I would like to queue email, which can be triggered from any number of backend processes, and then send those from a timer like service which runs as a windows service or possibly a back-end worker running in Azure via something like Functions.
Is there any way to leverage razor templates from within a RCL in a .NetCore console or other application which is NOT hosted in AspNetCore??
I think there isn't a way to do this i am sry. :(
If I understand your question correctly, you can use RazorEngine, which I used in .NET Framework 4.6.2 Class Library. There is a .Net Core Nuget as well.
I referenced such Class Library projects from Console Applications, Windows Services and Azure Cloud Services (Worker Roles).
In my setup, I had to mark Razor files as Content so they are copied over to the bin folder. Also, it got more complicated if library is referenced by another library and then that library is used; content did not get copied over or it got flattened out (all razor views ended up in the root of the bin folder vs following directory structures), for which there is a fix by editing project file and adding your own copy build tasks. Or I had to embed razor views into DLL.
There might be improvements to this in recent years, as I said I used RazorEngine few years back. And it might be different in .Net Core RCL as well, but I believe it is possible.
Nowadays, I am using 3rd party services like SendGrid or MailJet. For me, using them avoids majority of the above issues and offers better insight into emails/templates/campaigns to Marketing and other non-tech users. They can edit and modify templates to their liking without (m)any code deployments.
You have to run the code through ASP.net core engine so that Razor code get converted into html.
Otherwise use simple html template.

.NET 4.5 System.Web.Optimization bundling use on CDN

I'm building a CDN, and looking for a ways to utilize .NET minification/bundling mechanism (System.Web.Optimization) there.
The question is how can I return minified bundle from MVC controller.
Note: I'm looking to use native .NET 4.5 capabilities, I do not want 3rd party solutions.
I'm only looking for ways to utilize this on CDN side. Not on client application side.
Additional question: If the above is possible at all, please explain how can I take advantage of caching, which is normally achieved through adding unique query string parameter to request.
The asp.net bundling and minification uses WebGrease internally.
Grab it off nuget and add just start using it. It looks like the codeplex site doesnt have any examples on there so you will need to look at the source code or download/decompile the asp.net source code to see how they use it.
For the query string parameter I believe that is mainly to prevent/aid client side caching it doesnt neccessarily have anything to do with your server side.
You haven't said how you plant to serve up the JS files from your custom CDN so I can't help much with the caching, I would highly suggest not serving them through mvc though, there will be a lot of extra things happening in the pipeline that you dont really need if all you're doing is serving static files.
Perhaps look at having some process that parses the files and sticks them in a certain directory that IIS can serve directly without delegating to asp.net

following iterative and agile in asp.net MVC

ok, i know there are a lot of posts online that specify how to do iterations with MVC.
my question is slightly different. when i used to do iterations using WebForms, i was creating one thing only and finishing that one thing till the end which was including the deployment on production.
for example, i was creating a webpage and deploying it, then i create the second page and deploy it. so .dll files were added to my bin folder while the previous dlls remain untouched. at the other hand, when i was making a change latter on, there was this one file that needed to be replaced on production.
now here is the question, how can i acheive the same thing in mvc? beause it just doesn't deploy each page into an individual dll. each time that i add something i have to redeploy the application dll which is not really wise! i played around with deployment options in visual studio but no luck!
There is nothing preventing you from putting controllers and other code in separate assemblies and dropping them in an existing application. Like any ASP.NET based application an MVC application will automatically restart if you add or modify any file in the bin folder or modify web.config.
If you're using Razor you can use RazorGenerator to generate code for your views and compile them into the same assembly.
You may need to write some additional logic though to get routes, model binders etc. wired up correctly.
For a more structures approach to compose the application of separate modules, you may want to look into portable areas. This is an extension to ASP.NET MVC that allows you to package the entire module (including views, css, js etc.) into a single assembly.
First thing, you have to work on the title of the post, it does not match the content of the post.
In asp.net mvc u can choose to deploy only what changed. I.e. If you only changed the .cshtml file, then you can just replace it with the file in production. However if you change any controller class (C#/Vb code), then you will have to upload the web project dll file too so that this new changes are available in the production env

ASP.NET MVC 3 File Structure

I apologize for the vague title - I am new to ASP.NET MVC coming from PHP, and I have teamed up with a .NET developer that has a webforms background.
When working with MVC in PHP, all of my files are visible on the server - that is to say, I can go into any of my model, view and controller files and edit any of the code remotely without a problem.
In .NET MVC, I couldn't find the controller or model files, so I asked the developer how the webpage is being put together, and he told me about how .NET compiles code into .DLL files and that I am unable to access this. I wanted to view a controller to see how it was pulling together my views, but didn't even see a controller folder on the server.
To me, something about this doesn't sound right, but I am not sure because of my lack of experience in .NET. Can someone provide input as to if this is the typical .NET scenario, and if not, what is he doing wrong? Should I take this as a red flag? Keep in mind that .NET MVC is new to both of us.
Thanks!
There is no code files because these code files was compiled into DLL files during Publish process. It's not strange - it's even better because of performance reasons. It's common scenario for all ASP.NET and ASP.NET MVC applications.
You can deploy yor application via XCopy deployment (to have all .CS files etc.): simply copy all files to destination folder. Then your site will be compiled (into App_temp destination) by runtime on first run. Your .CS files will still be in place.
You can read more about Publishing procees here:
Walkthrough: Publishing a Web Site
Publishing Web Sites

Resources