Convert website to webapplication (User Controls) - asp.net

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.

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.

Create pages in published code

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

How to show Project folders in browser

I m working in asp.net. I have created folders in my project folder and I want this to show on browser so that when users click on folder name it lists down all the files residing inside that folder.
Below i am attaching a picture which is a perfect example of what I want to do.
I have never done anything like this so i want guidance for this.
By default, if you enable Directory Browsing in IIS, a user can view like this -
However, it is not what you want in ASP.Net Application. Instead, you need to create a page with GridView or other data bound control, and bind it with Data.
If you want too fancy, you want to go with Commercial Components like Telerik FileExplorer.

generating a dll of a web usercontrol

How can I make a dll of my web application usercontrol?
I have usercontrol222.ascx, but I want to make a dll out of this usercontrol.
Create a project containing only your user control ("usercontrol222.ascx") and grab the control's dll from the deployment of your new project. Here's the source of this method with a more complete explanation: Turning an .ascx User Control into a Redistributable Custom Control (Notable excerpts below, see the link for the full run-down).
Step 3: Use the Publish Command to Precompile the Site
The next step is to use the new
Publish command to precompile your
site and turn your user control into a
potential custom control. You'll find
the command under Build / Publish Web
Site. In the Publish dialog, do the
following:
Pick a Target Location. This is the location on your hard drive that your
site will be precompiled to.
Deselect "Allow this precompiled site to be updatable". In updatable
mode, only the code behind file (if
any) would get compiled, and the ascx
would be left unprocessed. This is
useful in some scenarios, but is not
what you want here since you want the
resulting DLL to be self-contained.
Select "Use fixed naming and single page assemblies". This will guarantee
that your user control will be
compiled into a single assembly that
will have a name based on the ascx
file. If you don't check this option,
your user control could be compiled
together with other pages and user
controls (if you had some), and the
assembly would receive a random name
that would be more difficult to work
with.
Step 4: Finding the Resulting Custom Control
Now, using the Windows
Explorer or a command-line window,
let's go to the directory you
specified as the target so we can see
what was generated. You will see a
number of files there, but let's focus
on the one that is relevant to our
goal of turning the user control into
a custom control.
In the "bin" directory, you will find
a file named something like
App_Web_MyTestUC.ascx.cdcab7d2.dll.
You are basically done, as this file
is your user control transformed into
a custom control! The only thing
that's left to do is to actually use
it.
You cannot. User controls are for the simplified scenario where you do not want to create a custom control. They have the disadvantage that the .ascx file and any other artifacts (images, styles, etc) must be included in each web site that uses the user control.
If you need complete reuse between projects, then you need to create a custom control. That's not actually that hard, if you directly translate the user control into a custom control.
You may want to look at developing your own server controls. See the following similar discussion: ASP.NET Web User Control Library.

Referencing code in VB.NET

I'm not at all familiar with VB.NET or ASP. I need to create a simple page which makes a call to a remote web service. I used the wsdl utility which comes with the DotNet SDK to generate a service proxy and write it to a VB file. Unfortunately I have no idea how to reference this code in either my ASPX file or the code behind VB file so I can create an instance of the proxy.
Edit: I should have qualified this by noting that I'm not using visual studio. I just coded up a .aspx with a .vb behind it and dropped it into an IIS location. Is there a way to do what you're suggesting outside of VS?
You need to add this code into your project so that it can be consumed.
Right click on your App_Code folder and select "Add Existing Item". This will bring up explorer. Use it to select the generated file and it will add it to your project.
Now you will be able to reference this code from within your page or code behind file
If there isn't an App_Code folder in your project, then right click on the project in solution explorer and select "Add New ASP.Net Folder"->App_Code
Or, instead of the wsdl utility:
In the solution explorer windows, r-click on the project, and select "add web reference". In the dialog that comes up, put in the url to the web service. In the web reference name box (lower right of that dialog), put in whatever you want to local alias for the service to be called.
So, if you put in a url of:
http://otherserver.com/otherservice.asmx
And, a web reference name of:
xyz
To use it, your code would look like:
dim x as new xyz
var = x.methodname()

Resources