How to access static content in an MVC Area? - c#

I have an MVC Area in a second Project (part of a different solution) and I cannot seem to find any way of accessing its Static Content when running my website.
Project 1 contains a normal MVC application which works fine.
Project 2 contains simply an Area. Project 2 is using RazorGenerator to compile the views, this project is referenced by Project 1 and is not in the same solution.
In Project 2 within my Area is a Content Folder with static images and styles. How can I get the main website to serve this content? I presume that I cannot because RazorGenerator is not able to compile non code files.
http://forums.asp.net/t/1534837.aspx?Static+content+in+Areas
In articles like above people simply manipulate the URL but this is not working for me, I get 404 for all because its not in the same solution.
How can I get this static content in Project 2 to be accessible to Project 1 given that I am using RazorGenerator to compile my views? I am aiming to make a self contained Area that I can add to other projects without needing to copy files over to support it.

Related

.net core 2.1 reusing _Layout throughout various projects

I am trying to reuse the same _Layout.cshtml file, throughout multiple .net core 2.1 Razor Page projects. Currently I have a Razor Page Class Library (Common shared project) that is where the _Layout.cshtml file will be located. Along with the layout file there are css and js files that should also be accessible to all other projects (I was able to make this work).
secondary projects will have references to the Common shared project and should be able to utilize the _Layout.cshtml file from it.
My issue is that currently it is not loading the common _layout file when I am accessing pages from these projects, instead it loads its own layout file. If I try deleting this file it throws the error that it cannot find the layout file. However, if I load a page contained inside of the Common shared project it does load its own _layout.
I have used the following tutorials to get where I am at but I could not figure out how to make the secondary projects load the layout in the Common shared project.
Including Static Resources In Razor Class Libraries In ASP.NET Core
Can Razor Class Library pack static files (js, css etc) too
Reuse UI With Razor Class Libraries (RCL) In ASP.NET Core
Please keep in mind that 2 of these articles are based on sharing the css and js files (which did work) but I have read up on other examples for the layout as well and have had no luck (currently I don't have the links to those other articles)
As far as what I have coded I'm currently experimenting on a sample project and its the same as the first article (Including Static Resources In Razor Class Libraries In ASP.NET Core).
UPDATE
Utilizing the 3rd link (Reuse UI With Razor Class Libraries (RCL) In ASP.NET Core) I was able to accomplish my goal. However, I was using this same strategy previously and it was not working. I am going to try playing around with this a bit more. If I have any other updates I will post them.
So apparently since I was working off of the Including Static Resources In Razor Class Libraries In ASP.NET Core link the example left the default razor page class library structure containing the Area/MyFeatures folders. I modified this to work like the last link Reuse UI With Razor Class Libraries (RCL) In ASP.NET Core where the Common shared project is structured the same way that the web application project is (no Area or MyFeatures folder). I also added:
#addTagHelper *,Microsoft.AspNetCore.Mvc.TagHelpers
to the end of my _ViewStart.cshtml located in the Common shared project.
Also just as a note you must delete the _layout.cshtml and _viewstart.cshtml from the web application otherwise it will override the shared project layout.
Anyhow this seems to have fixed the issue and it is now working.

Add Angular 4 seed project theme to asp.net core project

I need some certain views from a theme to be added to asp.net core project.
I was able to add the whole theme by
1. Adding css, js, images, email_templates, etc to the wwwroot folder from Full Project Folder (of the theme).
2. Then in Controller/HomeController.cs added a view to the index constructor which in my case the view was Views/Shared/_Layout.cshtml file (in which the code is from index.html of the template)
But then I was told to add only some theme files from the 'Seed' project of the template and only one certain dashboard and some other views specified which I don't know how to find them inside the theme.
I don't know how to proceed and where to start from. How can I get certain views from the theme and add them to asp.net core project ?
PS: I searched for tutorials or articles but they only show how to get the whole theme.
So, the way to do this was to copy all the folders and files provided by the theme to the ClientApp folder, in my main app, then run it using 'ng serve'. From there I was able to edit them and use it as I wanted.

Do Views get copied during a build of a DotNetNuke MVC Module based on the DNN project templates

I installed the DotNetNuke project templates for v 7,8,9 and added a new C# Compiled Module project. Whilst it seems that if I update the Controllers/Actions and compile then refresh the page I can see that the site is using the latest controller (because it's throwing an exception when I try to pass a different Model into the view).
But, compiling doesn't seem to update the views. The project template folders are placed directly in the DesktopModules/MyModule folder so I would have thought any changes made to a view would automatically be updated in the running site.
I've restarted IIS and it made no difference.
Howcome my views aren't updating?
Edit:
I just noticed now that during install DNN copies some of the MVC Module files to DesktopModules\MVC\MyModuleFolder. So the question now is: During development are you supposed to manually copy the view files from your project folder in the DesktopModules\MyModule\Views folder to the DesktopModules\MVC\MyModule\Views folder?
When using my MVC Template, you should use the path
/desktopmodules/mvc/ModuleName
instead of the path that gets used with all the OTHER templates.
/desktopmodules/ModuleName
Once you're using the right path, that should solve the "copy" problem, as nothing will need to be moved.

Convert Website to Web application With Visual Studio 2015

I have a Website Solution and I want Convert it to Web Application.
When I Transfer Base files (like DAL,BLL(.cs files my mean)) and Build My Solution it's working.
But When I Add other files that use the Base Files I have Many Errors Like (CS0246,CS0103,CS0118,CS1061).
I see this answer like:
https://msdn.microsoft.com/en-us/library/w7xf6dxs.aspx
and
Why am I getting error CS0246: The type or namespace name could not be found?
I want to Know if I build My Solution and Visual Studio Create .dll files why I have error that say not found X.dll? and how can it be fix?
You will have to go through and fix each error in turn as you migrate.
https://msdn.microsoft.com/en-us/library/aa983476(v=vs.100).aspx
I usually create an empty Web Application project and then copy the output into the same folder as my Web Site. Then I open the web application project in tye same solution as my website. Now you have two Projects for the same location.
Now enable the "show hidden files" option and "include" all the files in your project. At this point you will get loads of errors... Make sure that you first right-click on the root of your Web Application and select "Upgrade to Web Application" as this will do much of the grunt work for you.
In Web Applications you get Partial classes and when generated they are clashing with each other. In a Web Site you can have duplicate namespaces and class names, in a web application you can't. You need to go through all of your *.aspx and it's associated files and rename all of the class snakes to be unique.
This will start removing the errors although it may take some time to get through them all.

Visual Studio 2013 C#: one solution consume code of another solution

I have Java background and am trying to start on C#.
I wanna create a lib in C# that will be used in other solutions. In Eclipse it's just a matter of creating a jar and adding it to classpath. I know each project in VS2013 becomes a dll, but how can I make a solution see these dll?
Also, in Eclipse, we can create a Web Fragment Project. It can have Servlets, jsp and static js and css files, it becomes a war file and can be imported into another project and its files be used in that project.
How can I do that in VS2013? I'd like to create a solution with static files, master page, some aspx stuff, C# dll, and then use them all in other solutions.
Is there any tutorial (I googled it but found nothing) teaching how to do it?
You have a few options depending on your preferences and scope
Option 1 - The Class Library
You can create Class Library, that can be referenced in your website project. The Class library is a library of classes, interfaces, and value types
You can either Add an existing/New Class Library project to your website solution and reference it directly
You can add the project to your solution by right clicking the
solution (inside VS) -> Add -> Existing project -> and navigating to said
project's .csproj file
or
You can use a new/existing Class Library Project - build it and reference the built dll in your website solution.
you can right click your website solution (inside VS) -> Add -> new project -> choose Class Library
After you've done one of the above ->
Right click the project, you want to add the reference to
Click "Add Reference"
navigate to the .dll in question.
If the dll you want to reference is part of your current solution (as in step 1) -> after you've pressed "Add Reference" - press the "Solution" Tab and it should show up
After you've added the dll.
Remember to reference it in your code files with
Using TheReferenceNamespace;
which will allow you to call the functions inside you dll like the following
FunctionInsideDll(param);
or you could fully qualify your calls instead, like the following
TheReferenceNamespace.FunctionInsideDll(param);
Option 2 - Share MasterPages
if you just want "shareable" masterpages
you can do the following - (taken from this -> MSDN article)
(for future reference - web archive link - just in case something gets moved)
Precompile the Code Used in a Master Page
If you are concerned about code in your master pages being visible to others reusing the pages, you can precompile the master pages' code into a library. In this library, you can include code-behind pages as well as user or custom controls. Compiling master pages does not remove the declarative code for the master files or any server controls used, but you can compile the master files to remove the code for controls or code-behind pages used by the master pages.
If you choose to compile the master pages into a library, you must use the "updatable" build option that allows for later modification of the markup. This option is determined by the Allow the precompiled site to be updatable check box in the Publish Web Site dialog box. For more information about precompiling pages into a library that can be reused, see Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005.
Option 3 - The template
Create a template, and use that template for different projects
In Visual Studio - Press "File" -> Export Template -> follow the wizard.
After it has been exported and you've imported it (either through a checkmark in the wizard or double clicking the vsix file) -it will show up under your project templates when you create a new project.
You can include a project from solution A in solution B by right-clicking on solution B and choosing "Add existing project"
Don't be afraid to edit XML .csproj files. For instance, this works ...
<Compile Include="$(Codez)\z.Libraries\diff-match-patch\DiffMatchPatch\**\*.cs"
Exclude="NotThisOne.cs;**\NotThisFolderWith\This*.cs">
<Link>Libs\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
...and will give you all the C# files from the source folder, and subfolders, as linked files in your destination project under a folder called \Libs\.
$(Codez) is a Windows Environment Variable I use on my PCs.
I also could have used *.* at the end instead of *.cs.
This is one of those things Visual Studio might break on you, adding a file into the folder full of wildcard-linked files may break them out to separate entries. Or not. Depends on the wind.

Categories

Resources