Create pages in published code - asp.net

I want to know whether we can add new pages in depolyed MVC project code?
Based on my experience, it is not possible.
Please share your thoughts.
P.S: I need to add two new pages in published MVC code. So there is no chance to write any additional code in controller and model part.

Yes, you can add .cshtml to your publish folder in view, but you cann't add server side code in publish dll

Related

Where is the controller and view for the built-in authentication in ASP.NET?

I am learning ASP.NET coming from a Node.js background.
When I create a new MVC project, I can choose to have built-in register/login.
This gives me the following views, where I can register and login.
But I am confused as I cannot find the corresponding controller or views in the directory, which is problematic if I want to customize the behaviour.
Can someone shed the light on how this works and where are the controller and view? Thanks.
It is not in project folder. UI is loaded from Microsoft.AspNetCore.Identity.UI library.
You can check it's code in below URL. you can understand how to configure by looking at code.
https://github.com/dotnet/aspnetcore/tree/main/src/Identity/UI/src
They are not using MVC style, they are using Razor pages with code behind C# model.
You can provide your own UI by using attribute like [IdentityDefaultUI(typeof(LoginModel<>))] on your page model.
Reference:
https://github.com/dotnet/aspnetcore/blob/main/src/Identity/UI/src/Areas/Identity/Pages/V5/Account/Login.cshtml.cs
The controller folder contains the controller file in which you will see the server side(C#) code it will receive request from view and process on it and send back to view. And views folders contains the html code that get input from user. In this project structure, you will see shared folder that contains generic view files and _loginpartial.cshtml is login view.

Can I Create a Web API project with Single Page or Multi Page View(UI) without using MVC?

I Would like to create a project (basically Restful API Project) using Web API to target multiple customers from different platforms.
here I have a few requirements:
I should be able to Expose the API.
I would like to have the View(UI) also either single/multi page, (without using the MVC).
Right now I'm using one controller to refer to my View(index.cshtml), but I would like to remove that controller.so is there any other alternative to refer/use my UI Page without using MVC or should I use MVC along with Web API.
You can make a normal HTML file, or you can use Razor directly (via ASP.Net WebPages) without MVC.
Thanks Laks, with the help of your response:
I have created index.html page at root level and made it as the startup page.
when I run the project it has opened the index.html page.
as I wanted to open Index.cshtml file as startup page, I have moved my Index.cshtml page from Views/Home folder to root level and made it as startup page(removed previously created index.html) but it didn't work.
after searching few links in stack overflow, I got to know that directly accessing Razor Design(cshtml) files is disabled by default, and to enable this I have to change the following parameter in the web.config file:
Default:
add key="webpages:Enabled" value="false"
Change to:
add key="webpages:Enabled" value="true"
Now I'm able to access the Razor Design directly without any problems.
Please let me know if it is a bad practice to access Razor design(cshtml) files directly.
Thanks to Laks,

How do I call a root web form from a razor view inside Views folder in MVC project

I have to call web form located in the project root from the Home/Index view, below project structure:
I used the next code:
#Html.Partial("~/WebForm1");
but got the next error:
The partial view '~/WebForm1' was not found or no view engine supports the searched locations. The following locations were searched: ~/WebForm1, any idea please ?
To go into the views folder, use
#Html.Partial("~/Views/pathToYourView");
Or place your view in the "Shared" folder to reach the view with
#Html.Partial("ViewName");
like Forty-Two suggested.
Use this code
#Html.Partial("~/Views/pathToYourView");
the solution for MVC to recognize a Web form is to add its extension ".aspx"
#Html.Partial("~/WebForm1.aspx");

MVC3 - add a folder to controllers?

I want to learn is it possible to add additional folder to Controller folder. My reason is pretty simple: I want to divide my project administration and client sides.
Example: I have a controller named Post that has actions Index, Details, Delete, Create, Edit. I want to make one controller as user controller that will consist of Index, Details and another controller as admin controller that will consist of Delte, Create, Edit. Then I will be able to easy distinguish what is what and put admin validation on whole admin class.
Another reason is that I want my url for administrating my site to look like /admin/post/delete, not /post/delete.
So is it possible, and if so then what would be the best way to implement this?
Sound like you want to use MVC Areas? http://www.c-sharpcorner.com/UploadFile/b19d5a/areas-in-Asp-Net-mvc3/
It's just a convention on placing controllers in Controllers folder.
Actually MVC finds controller in current loaded assemblies.
You can place them even in other assemblies.
So, fell free to create additional folders inside Controllers
If you are using Ruby on Rails, yes, you can. In your routes files, config/routes.rb, add this:
map.namespace :admin do |admin|
admin.resources :posts
end
Go to your terminal and navigate to your project, run rake routes. Now you get your posts controller under admin namespace... and your url will be:
.../admin/posts

Convert website to webapplication (User Controls)

I'm developing a website in asp.net and now I need to convert it to a webapplication.
I created a new project with a new webapplication template and copy me files. I did a right click in the sollution and convert to webapplication and it worked fine, the vs2010 has created a design.vb files for each webform and it's good.
But, there are some webforms that uses some user controls and this user control doesn't created the declation in design.vb. I'd like to know if is there any way to fix the declations in webform to a my desing file to be used in code-behine ???
Thanks
You can right click on each user control and select Convert To Web Application (or something like that) individually to generate the designer files.
There is no easy way to do this through VS. You can alternatively try ReSharper's Adjust Namespace functionality.

Resources