i want connect mvc project with angular4 - c#

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.

Related

Serving .cshtml files on IIS globally

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)

NET.CORE and ASPX 404. Is it possible to host aspx files and bring them in with iframes in net core wwwroot folder

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?

Why can't I see the Controllers folder within my deployed MVC web app directory?

I have recently purchased a shared web hosting package, provided by GoDaddy, and deployed my own MVC web application to it.
My problem is that, when on the control panel (Plesk) provided by the host, I can't find the Controllers folder that contains all the behind code.
Is there a reason for this folder being hidden?
I'm guessing it's because the files within this folder are being used by the server all the time and can't be accessed/changed incase it f--ks everything up... But I am not sure about it because I am quite new to web hosting.
Thanks for any assistance in advance.
All your cs files including controllers will be compiled into DLL files. Please open "bin" directory to find all your DLLs.
When you deploy, u ll not get controller, because it contains c# code which changed to dll available inside bin folder.
Not Only Controller, the other folders which are having C# code like "App_Start"...and etc...will be changed to dll and will be available inside bin folder.
In the case of Model/s, if you are using Entity framework, then, the .edmx file will be available inside the Model folder.
All your Business logics including controllers, models and core etc are converted to dll and by Assembly name dll is created in bin (released or debug folder)

How does Asp.net 4.5.x MVC work with Angular 2?

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?

Deploying default.cshtml outside of MVC project

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.

Categories