I am using RazorEngine and Template functionality to prepare some pages as default.cshtml. These default.cshtml are very simple with some HTML/JS/CSS code and 1-2 lines of MVC if/else blocks. I need to deploy these files outside of the MVC project and directly under a blank asp.net website running 4.5.2 framework.
Can you please let me know what should be web.config entries and what assembly files are to be deployed in the bin folder. FYI: This website will not have anything except these default.cshtml and web.config/bin/etc., if required.
FYI: I am generating these default.cshmtl files using MVC 5.2.3.0, RazorEngine 3.7.2.0.
You pretty much answered your own question. If you've got a cshtml file, then you need MVC and Razor to render it. If you're using RazorEngine to generate them in the first place, then you could simply output them as *.html instead of *.cshtml, and then you wouldn't need anything. As long as it has Razor code that needs to be processed, you need MVC and Razor.
Related
I have a project solution in visual studio. Its created with MVC .net
I want to move some of my code files such as index.cshtml and others out of the Views>Home folder and into only Views folder. Will this break my project?
Also I want to rename index.cshtml to a new name, throughout all instances in my solution. When I tried this it only did the one file and it broke the project. I tried a CTRL F to find all index.cshtml, but it said there are no instances (though I know there are)
I need to rename the files correctly, so that I can deploy my project to match a current setup.
How do I rename all instances of index.cshtml in visual studio ?
And will moving the files outside of the home folder break the project?
I tried this it only did the one file and it broke the project. I tried a CTRL F to find all index.cshtml, but it said there are no instances (though I know there are)
If you just starting out I'd recommend not moving/renaming view files by hand. Eventually you'll have good understanding of how view discovery works and will be able to move files to places where they can be found at run-time (and even add more places yourself).
ASP.Net is convention-based approach to locate view files - short version is by default runtime looks for .cshtml files with this name format "/views/{controller name}/{action name}.cshtml", you can change view name by specifying different name when returning View("MyOtherView") from controller.
For detailed information on how view discovery works see Order in which Views are searched in MVC, how to change order of search viewLocation in asp.net mvc?, Microsoft - Views in ASP.NET Core MVC.
My Mvc project structure like that
and i want to connect angular with Mvc how can i do please help me
Basically, you can add Angular solution folder to your MVC solution wherever you want. MVC won't compile it and treat it as simple asset folder. Just create a new folder for your Angular solution is fine.
If you want to use Angular in your MVC project. In my opinion, you need to build your Angular. Copy the <app-root></app-root> tag to your *.cshtml file then include the three generate JS files: main, inline, polyfill from the "dist" folder into your *.cshtml.
I am trying to setup intranet IIS 8.5 (Win8.1) to globally serve .cshtml (Razor) files. The corresponding Application Pool is set to v4.0.
The files are simple Web Pages, not MVC. Here is an example of one:
<html>
<body>
#foreach (var i = 0; i < 10; i++)
{
<li>Item #i</li>
}
</body>
</html>
By removing the mapping of .cshtml files to System.Web.ForbiddenHandler on the IIS server's Handler Mappings I was able to get past the initial hurdle of ASP.NET telling me that
This type of file is not served.
However, the .cshtml files are now served verbatim to the browser, instead of being run through the Razor rendering process.
One would think that it should be easy to serve Razor pages from IIS, but it isn't. I need to somehow convince IIS to interpret these pages as Razor views; I suspect I am missing some mapping to the appropriate handler (I don't want MVC though - just simple Web Pages).
Here are some additional constraints:
I would definitely like to avoid including a bin folder with the requisite Razor assemblies in each of the sites on the server. The server hosts many sites, and I don't want to have to copy the bin folder everywhere. It should be possible to configure it globally, once and for all.
Ideally, I would not even need a local web.config for each site. The sites that are being served are a patchwork of technologies, containing .html, .shtml, .php, .asp, .aspx, and - hopefully - .cshtml files and should not be dependent on a single technology or config.
Creating a Visual Studio project is expressly out of the question. I should be able to use any text editor to modify the .cshtml files.
.NET Core is not installed on the machine and is not an option. Must use full Framework up to 4.6.2.
I am aware of many other SO questions that are similar, but don't quite solve my problem.
This question for example, was closed as "unclear" before it could have been answered, yet it was pretty clear to me! I am having the exact same problem.
The accepted answer to this question simply resorts to copying the bin folder. This is something I specifically don't want to do.
This answer says you can run an MVC application without installing MVC on your server, again by copying a bin folder into the local root. I do want to install Razor (but not necessarily MVC) onto my server globally.
Essentially, what I am trying to do is to use Razor syntax in a way reminiscent of classic ASP, or ASPX, without the baggage of MVC.
Can it be done?
I believe what you're looking for is a feature called ASP.NET Web Pages. If you use ASP.NET Core 2.0, the most recent new project templates uses Pages, rather than controllers and views. I've never read this doco, but I guess it should help you get started (or just create an ASP.NET Core 2.0 project from the new project wizard)
Fairly new to net core as we are currently migrating from .NET environment. Is there a way to add a folder(or simply drop aspx files into wwwroot of web app) and have it run side by side so url structure doesn't break.
I have even tried to add a folder with a sample file in wwwroot called test/test.html and it load fine BUT adding an aspx within the same folder and trying to run it returns 404 (test/file.aspx) yet the file is physically there?
The compilation and configuration is very standard of a plain project net core 1.1 web app and is enabled to use static files as test.html works, any ideas suggestions?
I'm learning to use Angular 2 with asp.net. I've got it to work, but I don't understand how it's working.
My understanding is that with MVC5, when you request a page from an action method of a controller, it will look inside the 'Views' folder for a html file with the same name as the action method and return it.
However, following this guide for setting up angular 2 in Visual Studio: https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html
I now have an 'app' folder that's sibling to the 'Views' folder. and an index.html that's in the root of the project folder. So how is it when I launch the app, the index.html from the project root is returned, and not the 'index.html' from the 'Views'->'Home' folder?
Also, this current setup seems a bit messy. Is there a way for me to move all the angular related stuff into one folder called 'client' for example?