What is Webprofile useful for? - asp.net

I stumbled upon this project ASP.NET WebProfile Generator
Why would I need proxy class to access profile?

Because ASP.NET only supports Profiles out-of-the-box with the Web Site option. If you are using a Web Application Project (WAP), then you have to roll your own.
The problem stems from the fact that the Web Application Project does not have the Profile object automatically added to each page as with the Web Site project, so we cannot get strongly-typed programmatic access to the profile properties defined in our web.config file.
Good news is that it's very doable:
ASP.NET: Web Site versus Web Application Project
How to add a Login, Roles and Profile system to an ASP.NET 2.0 app in only 24 lines of code
Web Profile Builder
Web Profile Builder for Web Application Projects
Writing a custom ASP.NET Profile class
ASP.NET Profiles in Web Application Projects

Related

Host a Web API under a Web Forms project

I have a ASP.NET Web APi project that uses an AngularJS as the front end. It is called "MyApiApp".
http://localhost/MyApiApp
I would like to move this project under another project that is an ASP.NET web forms website. It is called "MyWebForms" app.
http://localhost/MyWebFormsApp
My goal is to move the "MyApiApp" under the Web Forms app and access the "MyApiApp" as
http://localhost/MyWebFormsApp/MyApiApp
Is it possible to have an ASP.NET Web API hosted under an ASP.NET Web Forms project? I would like to be able to do this in Visual Studio where I could run that Web Forms application but have access to the "MyApiApp" app via the above URL.
Yes. You should be able to set it up as a virtual folder in IIS underneath the main website.
In the case of the VS Project, the built in web server doesn't support virtual folders, you'd have to set it up to run through actual IIS.
You should be able to have the WebAPI Controller as part of the main web forms project though.

Web API project template in VS

Why can't we create WebAPI project directly just like "WCF Service Application" template in VS.I want to create separate solution not using MVC or ASP.Net WebForms template. In our project we intend to have service layer on different physical machine hosted by IIS to be consumed by different web applications.
The ASP.NET team is in the process of making their offering more cohesive, an effort they call "One ASP.NET." Under One ASP.NET, MVC, Web Forms, Web API, SignalR, and Entity Framework are all first class citizens. They want to make it easy to create web applications that utilize these technologies without having to give up the others; that is, you can make an MVC project but still use Web Forms; or a Web Forms project can easily add a Web API Project.
Anyway, back to your question: you can't create a Web API project directly (i.e. it's not in the main project template list) anymore because it has been rolled into the the single ASP.NET project type.
They explain,
Starting with Visual Studio 2013, the guessing game about which
project type to choose is over. There is now only one web project type
in Visual Studio.
As you can see from the list of templates, we can choose to start with
a standard Web Forms, MVC, or Web API project type. The other project
types from the old MVC template dialog are still here. The interesting
part is the checkboxes underneath the list of templates. Here, we can
choose to add Web Forms references and folders to an MVC project, or
MVC references and folders to a Web Forms project. This is the gateway
to using more of these features in concert with each other in your
project.
Read the full MSDN blog article about One ASP.NET and the new project types here
You can, however, still create a project (or solution) that contains just the Web API references. Just use the ASP.NET project dialog to choose the Web API project type, and make sure all the other check boxes are unchecked. You'll be able to make your project just for Web API, and then go host it on a dedicated box for your services layer. It's all still there, the UI just looks a little different.

How to use ASP.NET legacy membership provider in ASP.NET MVC 4 application

I integrated a legacy ASP.NET 4 WebForms app with an ASP.NET MVC 4 app using VS2012 Update 4. The legacy app has security implemented via SQL Membership Provider. The legacy webForms pages are still secured in the newly integrated app, but the MVC views are not secured. For instance, a user cannot go to a .aspx page by directly using the page URL, say, http://myWebsite/SomeDir/Details.aspx but he/she can access a view, say, http://myWebsite/ControllerName/ActionMethod.
How can I secure the views using the same existing SQL Membership implementation that works on WebForms on this newly integrated web app.
You need to place [Authorize] attribute (either on the action method or controller) to protect it.

Using a custom membership provider together with Web Site Adminstration Tool

I've made a custom MembershipProvider which uses DependencyResolver from MVC3 to find it's dependencies. It works great for MVC apps, but not for the Web Site Adminstration Tool.
Is there some way that I can hook into the Web Site Adminstration Tool request handling to be able to configure a container before it handles the request?
Membership providers should be interoperable and therefore should work just by plugging into the config file of any provider based app.
Web Site Adminstration tool does exactly this, it runs in it's own web application completely decoupled from your MVC app, and just references your provider.
To make this work you need to ensure all dependencies required for the membership provider are packaged in one assembly and bootstrap your IoC container regardless of the environment it runs in. You can code this in such a way to share MVC initialisation, but not depend on it.

Why was the Profile provider not built into Web Apps?

If you create an ASP.NET web file project you have direct access to the Profile information in the web.config file. If you convert that to a Web App and have been using ProfileCommon etc. then you have to jump through a whole bunch of hoops to get your web app to work.
Why wasn't the Profile provider built into the ASP.NET web app projects like it was with the web file projects?
Actually, Microsoft does have a solution for this known issue.
It's the "Web Profiler Builder". I used it for my Web App and it works great.
http://code.msdn.microsoft.com/WebProfileBuilder/Release/ProjectReleases.aspx?ReleaseId=980
The profile provider uses the ASP.NET Build Provider system, which doesn't work with Web Application Projects.
Adding a customized BuildProvider
class to the Web.config file works in
an ASP.NET Web site but does not work
in an ASP.NET Web application project.
In a Web application project, the code
that is generated by the BuildProvider
class cannot be included in the
application.
source: MSDN Build Provider documentation

Resources