How to embed an ASP.NET Web Application into another? - asp.net

Providing web features through a custom HttpHandler such as in Elmah is extremely handy for ASP.NET Web Applications, because the handler can be embedded into any ASP.NET web app. It perfectly fits as a simple way to extend an existing web app.
Now, developing any significant set of features through a custom handler is a very tedious process. I am wondering if it is possible to directly embed an ASP.NET Application into another one through a custom handler (as opposed to cut and pasting the whole app in a sub directory).
Here is a small list of embedded web app that would be fit for such a purpose:
Health monitoring console.
Provisioning console (for cloud web app with auto-scaling).
App settings management console (considering a scheme IoC-settings-stored-in-DB).
Each one of those web parts could be provided as an HttpHandler; but again implementation is really tedious.
Does anyone know how to do that or how to achieve an equivalent behavior?

Do you usually put your features in a business logic DLL and just reference it from as many applications as need the business logic? What are you trying to reuse that this wouldn't work for?

Related

Asp.Net core Web API calling

I am new in Asp.net Core and trying to clear my concept on web api. I have basic knowledge on web api. I can do CRUD operation using web api by running that web api project and calling it in other web application project at a time.
My problem is,
I add an web api in a web application project named "Api_BusinessUnit".
How can I call this web api in a controller named "BusinessUnitController" shown in below image. My confusion is, Both are in a same project, I can run one project at a time. So how can I use this web api in "BusinessUnitController" ?
Thanks in advance.
Why do you want to have one Web API call another in the same project? If you need to communicate between parts of your project, you can do so directly without having to over the web, which will be much better from a performance perspective and will be more reliable as well.
That said, looking at your image, I think you have two separate web projects in the same solution which isn't the same thing at all (you may wish to update your question if this is the case). To have one project communicate with the other project, you should determine the URL of the destination project and call it as you are doing. You also will need to ensure both projects are running, of course. You can launch multiple projects at once when you hit F5/ctrl+F5 as shown here:
http://ardalis.com/how-to-start-multiple-projects-in-visual-studio
For me, I am a Scott Allen fan and he explains the project structure for the particular structure you are trying to create here.
https://odetocode.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx
However, I am a fan of best practices and SoC, so the proper way, IMHO, is to have one solution with multiple projects and either keep the entire solution in version control, or have the project solutions separate, build and deploy to a directory will all of them for testing.
Then the key factor to running MVC and WebApi as different projects in the same solution, besides making sure that Microsoft.AspNet.WebApi.Core is installed, is that the start up project is the MVC and the WebApi references that MVC. Then you're off to the races.

Possible to create ASP.NET MVC web site (vs web application)

I'm looking at the differences between a Web Site and a Web Application on MSDN, and am drawn to the features of a Web Site because I am tasked with devising an architecture in which customers can heavily customize the application we deliver. It seems this feature of web sites would be useful:
You want to be able to update individual files in production by just
copying new versions to the production server, or by editing the files
directly on the production server.
However, I'm also drawn to the MVC architecture because it has built in features for minifying scripts that are delivered to the client. I also kind of like the idea of breaking up the architecture into clean pieces since this is a very large data model we have.
But from what I can tell, these sets of features appear to be mutually exclusive. Is that true? I can't readily figure out how to create an MVC application in which custom views could be dropped in as pure source files, and be able to run, nor can I figure out how to take advantage of any MVC framework when creating a "Web Site" project. Am I missing something or do I have to pick my poison?
Take a look at ASP.NET templates in VS2013. You can create an app with both MVC and WebForms. This will probably give you a good combination of what you need. By default, view files are not compiled, so you'll always be able to publish new files without doing a full push if you want. In fact, VS2012 even allows you to publish select files or folders.
The choice between web site and web app to be is very simple. If you are creating a mostly static app, choose "web site". If you are creating an app that has even a decent amount of dynamic capabilities, choose "web app". Web Sites are not really designed to be dynamic, so the more dynamic you do in that setting, the more of a headache it will be to properly maintain it as the architecture just isn't where it would need to be.
What I would suggest is to spin both of them up and try out some scenarios that you are interested and see what works and what doesn't. Really think about how users will actually want to customize the app. Will they want to copy and paste files to production or would they rather request features and have them built properly? Or maybe they want to work with a workflow instead?
So make realistic business requirements, prototype and then decide. But based on what I'm hearing you want a WebApp and probably one that does MVC and WebForms.
Now everything ONE ASP.Net. You will be creating a WebForm, MVC, Webpages using ASP.Net platform.
Check this video about new features in VS 2013
Not sure you can create website in ASP.Net 4.5.
From my experience, I would go with WebApplication based project, where managing namespace and other stuffs are easy. In website its hard to get the standard name for the classes(randome) generated.
Go with MVC web application.

Multiple Application in Single AppDomain

I'm a web developer who's working in a new shop with developers from a desktop background - as such they have certain idiosyncrasies/best practices when it comes to organizing their code - one of which is that separate UI views are isolated into different projects.
So, on the web side of the house, I have a problem with different projects building in different app domains:
1) I have a "portal" project with a default.aspx
In the code behind there is a custom authentication method called from inside the Login_Authenticate event to log into the "business layer" of the desktop application. The business side stores session data in ASP.NET sessions.
2) I have a "viewer" project with default.aspx - this was originally in the portal project as "Viewer.aspx", where it was covered under the same login scheme and authenticated fine, but we decided it would be good to stand on it's own project because it is a separate view.
We added the same machine key to both web.config files so the .NET forms authentication could be passed via single sign on.
I built the viewer project in two different the fashions:
1st Try (it's own URL):
http://localhost/Viewer
2nd Try (a subdomain under the portal URL):
http://localhost/Portal/Viewer
The issue I'm running into is that the session is not being passed between the Portal project and the Viewer project. I know this is because IIS is running them in different app domains. Unfortunately without the ASP.NET session from the Portal, the Viewer is not logged into the business application.
Is there a best practice/is it even possible for running multiple projects in one app domain? Should the Viewer be a part of the Portal application since it requires the same session? Should the Viewer be a separate project that requires it's own separate login into the business layer? Is there even a best practice/guideline for this scenario?
By default session cannot be shared between different applications.
In practice most projects are not separated this way. In my experience most use some sort of n-tier architecture. Basically you have all your "view" code in one asp.net project, any buisness logic/data objects in another dll project, and your data access in a third dll project. The website then just references the other two dlls.
To solve your issue this answer might give you what you want: Sharing sessions across applications using the ASP.NET Session State Service
There is a way to have multiple projects, but one site. That example is a little old but still works, and is how we do our site.

combining jBPM in my spring-mvc application

I would like to control the flow of an existing spring MVC web project using jBPM. I think i want to make .bpmn file that each task opens a jsp web page. Is it possible? How do you combine your existing project to be managed by jBPM? Thanks,
You can create a workitemHandler to represent a web page and use the engine to redirect your application from one page to the other. But that's not exactly a business process (the real reason why BPMN2 was designed, it not to automate a web application flow). so you need to analyze if doing that kind of automation will give you the flexibility that you are looking for.
Cheers

Create one big web project or split some features into web services?

At what point (if at any) does it make sense to take some of the features of a .NET web application and split them into separate web services?
For example, we have a very large web application that also calls a series of long running operations (our core business logic). We also have a dll with client-specific custom features that is called directly from the web project. Sometimes we need to move very quickly to change these client functions, often in hours.
However, if we make a change to the client-specific features (or an emergency change to the core features) and publish a new project, then it would kick all the users out the system as the app restarts. It would seem like there's a better way ... but I'm not sure what it might be ...
First of all, it makes sense to remove everything from the web project that is not involved with the UI. Put that in separate class libraries.
Do not create web services unless some other application will be calling them. Simply placing the code into separate projects will be enough. Web services should only be created if they are a requirement.
I think it makes sense to create service app (not like Web Service, but more like Windows Service). You could communicate between your webapp and service app using Message Queue.

Resources