I'm just started asp.net using Razor V2 syntax. While I'm developing in Visual Studio, everything is fine however when i try to run .CSHTML files directly from browser, they do not work.
I want to know are .CSHTML files are intended to run directly or they must be used in other segments of web applications which can not be called by browser directly?
Yes - cshtml pages can be run directly. If you build an ASP.NET Web Pages (Razor) site, you can request .cshtml pages directly and they will be served (unless the file name starts with an underscore).
You can build a Razor Web Pages site by going to File » New » Web Site. You can get more information about ASP.NET Web Pages from here: http://www.asp.net/web-pages. It is the recommended starting point for people who are new to ASP.NET development.
[UPDATE]
They can also be run directly when used as part of a Razor Pages site which was introduced in ASP.NET Core 2.0.
By default mvc blocks access to views using an http handler in web.config.
Related
I've acquired a 1&1 Windows Business Hosting which allows to deploy ASP.NET Core applications (so yeah, I have no access to IIS solutions of building as application stuff or that kind of things I've seen in other posts). I wanted to deploy a web and an API in different subfolders within the 1&1 server I've acquired.
What I want to achieve is the following:
Imagine that my domain is https://myDomain. com.
If a user access directly that URL he should see a specific page of the Angular Web App. However, if the called is https://myDomain. com/api/controllerName it should do whatever I have programmed in that controller of the Web API.
I want to have the folder structure something like this:
But it is also valid if I manage to get it like this:
Is any of these two cases even possible to be done? If possible, how I should proceed for being able to do it? I don't have a lot of knowledge in these topics related to web deployment.
What I have managed to do up until now:
If I deploy just the ASP.NET Core Web API outside the subfolder it works with no issues. If I deploy just the ASP.NET Core with Angular outside the subfolder it also works. My issue is that I'm unable to get them both to work at the same time when at least one of them is in a subfolder.
Alternatives on how to achieve this are also welcome!
Thanks in advance :)
You can deploy ASP.NET Core Web API and ASP.NET Core with Angular in two folders as shown in the image below.
These two folders are virtual directories in IIS. If you want to specify which app to access by default, you can modify the rewrite rule in web.config under the wwwroot folder.
I've been reading about Razor Pages and the idea of being liberated from JavaScript is very compelling. From what I've gathered, while a Blazor client uses the same libraries as the rest of ASP.NET Core, it is a seperate ASP.NET Core web platform.
Is possible to add a Blazor page within an ASP.NET Core MVC application? Why wasn't it developed as an addition to the existing ASP.NET Core platform, instead of a seperate platform?
No, you can't "run Blazor client page within ASP.NET MVC Core page."
The concept of page in Blazor does not exist, unless you mean a Document Page displayed in the browser.
Blazor is focused around the concept of Components: Blazor Component Model.
Yes, you can embed Blazor Components in an MVC app or Razor Pages App.
This is how to do that:
Add a call to an Html helper method which render the Component. Here the component is one that actually contains the rest of the components in a Blazor application (App.razor), which is why the whole Blazor app is going to be rendered in a Razor Pages Application.
Note: This is not Blazor... In Blazor we've got no Html Helpers
<app>#(await Html.RenderStaticComponentAsync<App>())</app>
Below is a link to the page where it is used:
https://github.com/danroth27/ClientSideBlazorWithPrerendering/blob/master/ClientSideBlazorWithPrerendering.Server/Pages/_Host.cshtml
Note that _Host.cshtml is not a Blazor Component. It is, again, a Razor Pages page.
Note that in the sample a whole Blazor app is actually rendered, but of course you can use a normal simple Blazor component (one or more, unrelated components, or related ones, that is, parent component with child components). The principal is the same.
Hope this helps...
Yes. It is possible to run Blazor client page within ASP.NET MVC Core page.
This is simply because Client-side Blazor is like having React application in your MVC Core application. They are completely separate things. Client-side Blazor works in the browser. This is means that MVC create HTML page which run Client Blazor in same way, as MVC creates HTML page to running React application. Just inject some framework specific magic.
For Blazor this means adding at least.
<app>Loading...</app>
<script src="_framework/blazor.webassembly.js"></script>
and code on the server.
app.UseClientSideBlazorFiles<Client.Startup>();
app.UseEndpoints(endpoints =>
{
// ...
endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
});
Microsoft calls this model in the templates as Hosted Blazor.
Since MVC executed on the server, the only way to have run Blazor code as part of MVC framework is to use Server-side Blazor, because it should be executed on the server. Again, because MVC executed on the server.
If you really want to run Blazor as part of MVC application, then you should publish standalone Client Blazor application and treat output as some JS library which you have to serve, using standard MVC means, and inject in the page somehow. That's still doable, but you on your own.
I have an existing vb.net web application, I want to add some C#.net web pages in that application. I don't want to create subsite for that pages.
It is possible and we are also managing some projects which has 2 languages(VB,C#) for web application.
What i suggest is to copy the vb web page to the project folder and include them to project.(include .vb,.designer.vb)
now just build the application and set the start up page as the newly added vb web page.
I hope it should work.
cheers.:)
I created a new project based on the Web API template, but found that it include a lot of unnecessary files that I don't need such as the regular mvc routes, css, js, cshtml files. I wanted a pure asp.net Web API application, What can I delete from this project template?
This is pretty annoying - there is no "empty" template for WebAPI by default so you have to delete the following:
/Areas/
/Content/
/Images/
/Scripts/
/Views/
favicon.ico
This should leave you with the default generated Controllers and App_Start folders which, along with the Global.asax & Web.Config is the only thing you really need for a plain WebAPI project.
I haven't tried this, but it claims to provide a real empty WebAPI template:
http://visualstudiogallery.msdn.microsoft.com/a989a149-4bc3-4292-ac8a-5101ee1722d7
I have a c# .net VS2010 web application that contains only classic asp files.
What I want to do is convert the web application to a web site to make it easier to manage the classic asp files.
How can I convert from web application to web site? I have researched google and found lots of examples going the other way.
I don't think there's an automated way to do this. You could just create a new website in Visual Studio and copy your files from the web app into this new website. Be sure to go into each and every .aspx/.ascx file and edit the 'Codebehind' attribute so that it reads 'Codefile' (codebehind directive needs to be compiled and thus won't work in an ASP.NET website). You'll also need to delete the Designer/Designer.cs files.
Hopefully you don't have too many files so that this won't be too much of a PITA.