I'm currently refactoring a huge ASP.NET MVC website. The main idea of what I'm trying to achieve is having a main (front) website and several separate websites in the same solution that can be deployed separately. The reason for that is that we have different teams working on a different project.
The current setup looks like this:
Main website ASP.NET MVC
Module 1 (Area)
Module 2 (Area)
other modules..
Common Business Layer
Common Data Layer
Common View Layer
When making changes to a module, you have to deploy the main website (so although Areas are acting as separate projects, they cannot be deployed separately). Areas are using RazorGenerator for the views. The Common View Layer generates Embedded Resources to be used in the main website/modules.
Any solution for that?
What I'm trying to accomplish right now is extracting the modules from Areas into full ASP.NET MVC websites and map them in IIS as subdomains to the main website. The problem here is that I have repeating views, styles, layouts in all projects and making a change to the main menu, style, etc. would mean going through all the projects and make that same change. Not a viable option.
Thanks for the ideas!
So the answer can depend also whether you want to have several solutions (*.sln) or it will be just one solution with several mvc projects.
Ad.1 Multiple sln / directories.
In that case probably interesting option is to configure virtual directory with some static content like styles, scripts etc. Such virtual directory can be quite easily configured on IIS: https://msdn.microsoft.com/en-us/library/bb763173.aspx
Ad.2 One solution, multiple MVC projects:
Then I'd suggest to add some solution folder like 'Common Presentation Layer Files' -> then I'd move all those files to be shared into that solution folder. Next in those MVC projects I would do following thing => right click => add existing item => as a link.
As the result you'll have a copies / shortcuts to the original files. You should do the updates only in that common folder and the changes will be visible in all other mvc projects. https://msdn.microsoft.com/pl-pl/library/9f4t9t92(v=vs.90).aspx Then you can publish your MVC projects separately and if properties of those static files are ok all the files will be copied during publish. So the structure would look like:
Solution:
MVC App 1 (proj)
MVC App 2 (proj)
'Common Presentation Layer Files' (solution folder)
other projects (projs)
Related
I'm unable to get server side includes (*.html files) working in a .net core razor pages web application. I've made sure to have the appropriate handler in my applicationhost.config, but I'm thinking there's a different issue here. Any help is appreciated.
Why am I doing this? I have multiple web applications sharing the server side include files (for navigation bar, footer, head content, etc..). Each of these different applications may be of different Microsoft web architecture. Our goal is to move everything to .net core, but we have lingering web forms projects to deal with along the way.
I have performed a work around by taking the SSI file contents and using #Html.Raw to serve up the content. This is probably wrong also.
I went ahead and changed the file extension of the html files into cshtml which allowed me to treat these files as partial views. I'm using a prebuild event to copy these files from a shared solution folder into my project Pages/Shared/ssi folder. I also copy those partials into wwwroot/ssi for the other applications to use via SSI. Eventually all of the apps will use the partial views instead.
The problem with this solution is that it is not necessarily clear that all edits need to happen in the shared solution folder instead of directly in the project, but the documentation for the project will address this. I tried using linked files, but only one link to a specific file can be made in a project.
Not a perfect solution (to the problem), but this not a perfect website either.
I am making a class library in asp.net , is there any possibility to add web forms in class library ( content view files with their code-behind ) so i can run , only with a simple method in the CALLER PROJECT ,a whole web app (thanks to this class library) .
I searched and i found i can't but If not , is there any near solution which can solve this problem ?
Thanks !
is there any possibility to make a class library as a web app "template" that we can use every time we call it in another project
A "class library" project, in Visual Studio terms, is strictly namespaces and classes - no web forms or controls allowed. And you're right, these projects are easily shared among sites by leaving them in a common source control repository or similar.
In an "ASP.NET Web Forms Web Application" project, you can reduce duplication by moving as much "code behind" code as possible to class libraries, which can then be shared among your team(s). You could even theoretically implement a lot of page/control functionality as "base classes" stored in class libraries and then inherited in aspx.cs and master.cs "code behind" files.
You could also move as much "code front" as possible into Custom User Controls which could be shared across projects by linking source control to a common repository.
But I don't think there's a good way to "share" .master and .aspx files. You could set up a basic website, keep it in a common place, and let people copy/paste it for new projects. But I don't know of a useful way to share that UI code among multiple web app projects.
I am starting to create a complete application in Visual Studio (.NET MVC). Does it makes sense if I put everything into a single solution and create three separate projects: Admin (used by staff to manage the app data), Web (public facing web pages), Shared (common data access and other code). This seems to make sense as later I might add a project for Mobile or an API or ...
If not, how do you structure your solutions/projects in Visual Studio?
If it were me, I'd have everything in one project and use areas to separate my views and models.
Example,
Project
Areas
Admin
Controllers
AdminController.cs
Models
Admin.cs
Main
Controllers
MainController.cs
Models
Main.cs
LoginLogout.cs
LoginForm.cs
Views
Admin
Shared
permissions.cshtml
admin.cshtml
Main
Shared
loginLogout.cshtml
loginForm.cshtml
master.cshtml
Index.cshtml
Walkthrough: Organizing an ASP.NET MVC Application using Areas
Areas provides a really nice way to section off pieces of your web application, and because it's all in the same project you can have all your sections use the same View Layout (Master Page) to make it all look the same from section to section.
Areas will map to urls like
http://somesite/main/index
http://somesite/admin/manage/index
In that example, you would not put your main section in an area, instead use normal model view controller patterns for the main part of the site, and only introduce an area for admin or other sections.
I know how to use areas in MVC3 - and I think it works very well, but I really want to make a higher level of seperation in my project.
I have multiple projects in an empty solution, a Domain project (containing my entities, persistence etc.) - a Framework project with tools, helpers etc.) and a UI project which right now contains the frontend and an area with the /admin for the solution.
Because a want to have a more clean solution for the UI and the Admin, I want to seperate these into two seperate projects.
How can I route the URL?
The url / is pointing at the frontend project.
The url /admin is pointing af the backend project.
Your /admin is nothing more than another virtual directory mapped to your admin app. It should work just fine like that, as it's how iis and asp.net works.
I’m starting to learn MVC3 and I’d like to know if it is advisable to group your views and controllers in folders different to the default ones.
So I could organize the project such as:
-->ClientsFolder
-Views
----ClientsAdmin(Folder)
------View1
------View2
------View3
----ClientInvoices(Folder)
------View1
------View2
------View3
-Controllers
----ClientsAdminController(File)
----ClientsInvoiceController(File)
-->EmployeesFolder
Etc..
Etc..
I’d like to know, if it is a common practise, how should I start to adapt the project to this structure or if somebody could point me to a tutorial which could help me started.
Thanks
What you are describing is a feature MVC 3 already has (since MVC 2 I think). Areas.
Walkthrough: Organizing an Application using Areas
UPDATE: New working link.
What you are doing is fine. There's no need for a new area for every controller, areas should be for large chunks of application that aren't really the main application (like an administration site for your main site).
This is an OK tutorial to get started MVC Movie Tutorial
ASP.NET MVC has a facility to partition Web applications into smaller units with areas.
For example you can create an admin area for the administration section.
There are Areas for arrange mvc project.
Don't invent the wheel again... =)