Adding Azure Single-Sign-On to an existing MVC application, in VS2013 - asp.net-mvc

I've been exploring the Azure Active Directory services and was pleased with how easy it was to hook up an arbitrary ASP.NET MVC website to it. I've experimented with this in Visual Studio 2012 and all works well. Especially using the Identity and Access Tool extension for VS2012.
Now here comes the tricky part: This tool is however deprecated and not supported on, nor available for Visual Studio 2013.
There are several MSDN documents on the matter, like this excellent tutorial, only I find them all targeting VS2012 and the forementioned tool. For new projects the process is "simplified when creating a new web application". But I don't want a new application - I want to hook up existing applications in VS2013.
Now the question is: is there a 'decent' way to integrate Azure ActiveDirectory, especially the Single Sign-On feature, to an existing ASP.NET MVC 5 web application in Visual Studio 2013?
At least with the same ease as the I&A Tool, but without the need to recreate or migrate my entire application, of course.

Depending on the complexity of your project, you can either create a new project and import your project files to the new project or import the identity settings to your existing project.
Since the identity controls are really just a set of files and configuration, you should be able to create a project with the identity settings you want and then copy over the files / configuration to your existing project. You may also need to add references to things like Microsoft.AspNet.Identity.Owin and any security providers you need. Files to take a look at include:
App_Start/IdentityConfig.cs
App_Start/Startup.Auth.cs
Controllers/AccountController.cs
Startup.cs
Web.config
Yes, it's a pain, and hopefully there will be an easier way of adding or changing identity later, but this is the best I've come up with for now.

Related

Updated ASP.NET Web Application (.NET Framework) MVC5 Project Template

The project that visual studio 2019 creates for an ASP.NET Web Application (.NET Framework) MVC5 comes with Bootstrap 3.x and many other outdated components. Not to mention unneeded things like modernizr.
If you update Bootstrap, you know need to modify the ScriptBundle in BundleConfig to get the application to start, and then modify the CSS to get the premade web pages to render properly.
Also, the folder structure is not the best.
Is there a project template out there that has all essential components updated, and a clean-up NuGet and folder structure?
I tried using Rider but they do not have a built-in template.
I went t the .Net Foundation GitHub and did not find any: https://github.com/dotnet?q=.NET+framework&type=&language=c%23&sort=
I also search GitHubub and did not see any: https://github.com/search?q=ASP.NET+Web+Application+%28.NET+Framework%29+project+template
I am looking for a project template that has the basic structure to create a Clean Architecture in .NET Framework and not .NET Core
I know it's legacy, but unfortunately, I need it for a university class (University courses take a while to get updated, and in this case, they claim that there are sufficient companies out there using ASP.NET MVC 5 to Merrit them teaching it) But yes, No one should be using this to start a new project they intend to put into a real-life production scenario.
Thank you

How to create custom TFS check-in policies in .NET Core 2.0?

I'm familiar with the new deployment/installation design of VS 2017, and the way it leaves no footprint on registry.
And I'm also familiar with how we need to change our check-in policy installation from registry manipulation to VS extension creation.
However, now I need to create check-in policies in .NET Core 2.0. The problem is that I need to use Microsoft.TeamFoundation.VersionControl.Client dll to be able to access PolicyBase and also PendingChange classes. This results in FileNotFoundException.
Also I need to use Mono.Cecil as the reflection library, to be able to process things in more detail before checking-in. I can't find if Mono.Cecil supports .NET Core 2.0 or not. Nuget page is not informative and the libraries page on GitHub is also not easy to understand.
And another obstacle is to create a VS Extension. I can't find out the required package definition items to be added to source control.
Can you please provide a simple example of how to create a custom TFS Check-in Policy in VS 2017 via .NET Core 2.0?
Since the policy ends up running in the context of Visual Studio itself, I believe you have to be compatible with the .NET framework that Visual Studio is running in, and that is the "classic" .NET Framework, not .NET Core. Libraries written to a .NET Standard can potentially be consumed by both .NET Framework and .NET Core applications, and I believe you could also include separate executables in an extension and run them as separate processes if there's some piece that absolutely must run in a .NET Core environment, but you can't mix-and-match within a single process, and the extension code itself doesn't get a choice: it runs in the Visual Studio process.

How to add Azure AD Authentication to Existing ASP.NET MVC Application?

I have an existing ASP.NET MVC application using Visual Studio 2013. I followed this walk-through but it only concerns itself with a new greenfield project while selecting Change Authentication in project template: Developing ASP.NET Apps with Windows Azure Active Directory
I am not interested in using OWIN and OpenID Connect Katana modules as these components have lots of issues so I am waiting for that technology to mature and render out all the current problems.
I aim is understand how to manually add all the components and configuration to my existing ASP.NET MVC application to achieve the same Azure AD authentication model in Rick Anderson's article.
The tooling in VS 2013 doesn't support adding this to an existing project. At the bottom of the link you referenced in the More Information section is a deep dive article where I dissect the code and configuration that gets added. So, you could use that as a reference to find the deltas and apply them to your project.
Now, Visual Studio 2015 offers us some hope in this scenario. It's in preview of course, but you may give it a try. In Solution Explorer, right click on your existing project and select the Configure Azure AD Authentication option.
In Visual Studio 2017 the option to enable Authentication with Azure Active Directory is in Connected Services:

How do you properly get/deploy ASP.NET MVC?

I'm thoroughly confused about how to properly deploy ASP.NET MVC with my application. As far as I understand, there are the following ways you can get it on a machine:
You can download a separate installer and install it on a machine that has the approprite .NET framework (although which MVC version requires which .NET framework?)
Some versions come along with .NET framework itself (though I can't find which version of MVC is shipped with which version of .NET);
Some versions are installed with Visual Studio (though again, no idea which versions are installed with which versions of VS). In this case, you can set Copy Locally to true for these references and perform a "bin deploy". You might need to add some extra references though (not sure which though).
You can also download MVC as a NuGet package, in which case it also downloads some other unrelated packages like WebPages, Infrastructure and Razor (which is my personal WTF - wasn't Razor a core part of MVC?). In this case the build process will automatically do a "bin deploy" by default (I think...)
So... WTF? What is the proper way to add MVC to your development workstation, what is the proper way to add the references to your project (NuGet? GAC?), and what is the proper way to deploy it to the target server (separate installer? .NET installer? bin deploy?)
"Proper" Development:
The "proper way" (by which I mean standard/redistributable way) would be using Nuget for your references. This means you can easily manage different versions and anybody else working on your project has a standard repository from which to pull the external requirements.
The NuGet documentation has a decent explanation of how to add references.
To install the appropriate version of MVC for developing through Visual Studio, just download and install it from the ASP.NET MVC website. This will install the necessary templates for you to create a new MVC project in Visual Studio. This will also include the necessary binaries, etc.
"Proper" Deployment:
Use bin deploy to deploy to your webserver. This means you don't need full admin priviledges to install the MVC requirements.
Phil Haack's guide will walk you through the process of bin deploying MVC3+
Keep in mind, the web server does need the appropriate .NET platform installed. You should install this via the appropriate redistributable installer if it is not already installed on the server.
Referring to the deployment i publish my asp.net app (i usually make web applications) to the file system in a directory (you can set also a server there, but i don't like it) and make an upload to the server with an FTP client of all the deployed folders. All the changes that i make to the app after (like bug correction) i deploy all the app again and upload single parts.
I hope i get your question in part, this is my first answer in SO.

Debugging a nuget of an entire web installed into an empty web app

We are in the middle of development for a core ASP.NET MVC web project and a customer plugin in the form of an MvcContrib plugin web project -- a web project injected into the core web as an area. The plugin is a soft reference in the core project, so it can be developed completely separately and dropped in.
I am trying to generate a way to debug/code the plugin, so that the multiple custom plugins can be developed independent of the core web.
The developers should only have to worry about coding and testing the plugin code. Also, I don't want them to change the core code in this custom plugin project -- that should be done in the core anyway.
I created the core web as a NuGet package and included all the necessary files so I could include it in a web.
My thinking was that I could create an empty web, install my core web, and the developers could have an F5-driven debugging environment.
I tested by creating a blank Mvc project, installed my core package and included one of my plugins. I changed the namespace of this empty web app to the namespace of the core web, thinking that Visual Studio debugging would properly attach and my core assembly.
Simple VS debugging in the empty app does not work -- I receive an HTTP Exception, most likely due to my routes not being registered. I also see that my log4net is not creating its logs folder, so I know the assembly's app start is not being called.
So I see that VS is not attaching to and calling my core assembly.
Can I use this empty web as a host project for my nuget installed web and debug? If so, what configuration am I missing?
If not, how can I include the core web in each customer plugin project in such a way that I can drop my DLL into the bin and debug it?
Using:
Visual Studio 2010
ASP.NET MVC2
The way we are doing things that works pretty well is to use a combination of Web Activator and Razor Generator (available as a Visual Studio extension). In order to access the views within the core web application, the consuming client application needs to know about them, either because they are all included as file references inside the Nuget package (messy) or because they are compiled into the core web dll. You can do that using Razor Generator. Once installed via Nuget you would need to change the Custom Tool property for each .cshtml file to RazorGenerator, which will create a .generated.cs file for each view. This will allow your sample client to use the layout and views from the core web application.
David Ebbo has some useful blog posts on Razor Generator
Couple that with Web Activator to create a PostActivationStartMethod that runs your initialisation code (such as initialising Log4Net) and you should be good to go. We've had this running in 2 scenarios - consuming the framework package via Nuget and adding a project reference directly. Debugging was not working for the Nuget package consuming route but we don't include the pdb files in the Nuget package. We can debug when adding a project reference directly though.

Resources