Reference web projects from other web projects in solution - asp.net

I am working in Visual Studio 2013/2015. I have three web projects in my solution. I want these web projects to be able to make calls to each other, which means that they need to know at what port they are hosted on during development.
I am hosting in IIS Express, which by default means that they get auto-assigned ports. This is good because if a port is unavailable, another port will be used. Since the port is determined at runtime I cannot have a configuration file in each projects which says where the other projects are hosted.
Other than manually assigning ports, is it possible to somehow reference these other web projects from one web project and then make calls where the used port is substituted?

Related

Manage localhost ports when developing with Visual Studio with several users on one machine

In our Visual Studio development (VS2015), we share one virtualized machine with several developers. We had to solve several minor problems with this setup but discovered a more annoying problem now.
Our solution consists of a client that uses web services, that are implemented in a ASP.NET project. When we start our client, we also start the services so that the calls can be made from the client. The services get started on the localhost port that is entered in the project properties. But when we work with several developers we have the problem that Visual Studio would use the same port for all developers and as we are on the same machine, the web project will not start because the port is already used. We now have following questions:
We can separate the ports by editing the IIS config file but we also have to change the port in the client and after each checkin all developers again have the same port.
1) Is there a clever way to manage the ports in the local IIS express?
2) How can we configure the ports in the clients so that the configuration is not overwritten by each checkin of other developers?

How to deploy a single solution with multiple projects?

I have developed a well-decoupled website using WebAPI and AngularJS as follows:
SOLUTION
|—— WEB.API Project
|—— Website pages Project
'—— Other projects related to functionalities
This setup is on my own computer.
Now I'm here wanting to deploy to my web server (iis 7.5, privately owned, WebDeploy installed). It is possible to deploy both projects on a single web site? (other projects are class libraries, so no hassle)
For what I know, I have to deploy the WebAPI part to a website, and the UI part to another website. May I put them on a single website?
You can put the Web API project in a virtual directory under the main web site. That's what we are actually doing in our current project.
You can, but you should be worried when files conflict. If both projects have a web.config for example, this could break either of them.
If not, it should be possible, but I wouldn't immediately recommend it. I would split them off in separate virtual directories so you can maintain the two separate projects easily.
You could also self-host the Web API using OWIN, so you wouldn't then need to set up a project in IIS etc and you could then have multiple clients talking to the same API.
There's a tutorial here which is more advanced.
I have a near identical project setup. Personally I picked 2 separate apps, I have a multi server setup with load balancers - the choice may have been different if I had a single server or low amount of expected traffic.
This gives the advantage:
I expected my WebAPI to have a larger amount of traffic than the web pages, due to mobile clients also consuming the WebAPI as well as the front end webpages. Because the API is in its own website, it has its own app pool - this means that each application has its own resource pool (app can grow to use more memory and CPU better), not shared like they would be on a virtual directory.
Disadvantages:
Because there is two separate app pools, I have one bound to port 80 and the other to port 8080. As I had a large server farm to roll this out on, I already had a load balancer in front of the webservers - hence to make the URL pretty (i.e. drop the port 8080 from the URL) i added a load balancer config to allow traffic to come in on a given url on port 80 and be redirected to port 8080 on the internal webservers. This isn't really a issue if you don't mind ports in your URL's.

Starting .Net web service on the same port as the ASP.Net application

We have a simple Visual Studio solution containing 2 projects:
A.) Simple ASP.Net website
B.) RESTful web service hosted in another ASP.Net application
We want to simply start the projects in Debug mode (F5) and have A consume data from B through Ajax. We do not have the possibility to configure IIS on all development machines (because some of them are on the client's side). The problem might be that JavaScript needs to be in the same domain as the URL it posts to.
Is there any way we can use Visual Studio 2010 Development Server to start both applications simultaneously in debug mode on the same port?
If this is not possible, what is the next best thing you can recommend?
We solved this problem by installing IIS on the development workstation.
In each Visual Studio project, on the Web property page, select Use Local IIS Web server.
Do not check Use IIS Express. The Project URLs will be set to http:localhost/<projectname> (note: in the same domain). You’ll be prompted to Create a Virtual Directory for each. Each will be assigned to the default IIS app pool. Open the Internet Information Services (IIS) Manager. Click Application Pools on the left pane. On the right pane add another integrated application pool. For one of the applications, open the Advanced Settings... In the properties view select the app pool you just created as the application pool. The applications should be debuggable in parallel because each Application Pool spawns a new operating system process to which a separate debugger can be attached.
Yo won't be able to host different apps on the same port within a Cassini instance, there are tools that might be useful but I would leave Cassini host them on different ports which is its regular behavior.
Options are (not tested):
UltiDev
Cassini Extesion
By the way, not sure if you know this, but to start both projects go to Set startup projects, there's an option on the Solution context menu.

Want to run my own server instance with special port for an ASP.Net 4 based solution

I have made an application in asp.net which sends and receive sms, it works very similar to desktop application and it will be installed on servers to send sms alerts, but the problem is if server does not have iis, it will not work. I have seen many apps which when installed, have their own server and port, you do not need to install any IIS, when you just double click it starts running on a special port and works well, similarly visual studio also runs its own port in development mod, so what is the best way to make such solution for an asp.net product.
If you're talking about how to host a service in an application outside IIS, Windows Communication Foundation (WCF), which allows you to host a service in a Windows Forms executable, Console Application, Windows service, or IIS.
It's too big a subject to explain fully here, but there's a nice starting point here.
This will allow you to create the host, and allow you to hose services similar to web services, but with more options for how to connect. (http, tcp, etc.)
But it's not an ASP.NET host. For that, you will need a web server that can execute ASP.NET, such as IIS. There's no way to get around the need to have a web server, whether it's one of the many already established, or if you write your own. I believe there are extensions for Apache that allow you to do so via Mono, but I've never used them. Writing your own would be, in my opinion, a waste of time and a bad idea.
The simplest solution by far is to specify that IIS instaled with the appropriate framework is a requirement for using your website.
Edit
However, if you REALY want to write a WinForms app and have it host ASP.NET, it looks like this previous question has an answer that would help. You can use the Cassini web server, the same one that Visual Studio uses.

How to run a leightweight ASP.NET MVC application that would be accessible only locally (not on IIS)?

We have a desktop client application and recent customer requests indicate that they would like to have some dynamic HTML content served and displayed by the application.
We are considering hosting a simple ASP.NET application in a local process, accessible only from the local machine (similar to the ASP.NET development web server used when debugging from Visual Studio).
How can we run an ASP.NET application locally without IIS? IIS is not an option because most client machines will not have it installed.
Is there a leightweight ASP.NET web server that could run locally similar to the development web server that VS is using?
I have found some information about "Cassini". Is this suitable for production use? Can it handle ASP.NET MVC? Are there any alternatives we should consider?
I have not used it myself, but you can try the mono XPS server.
It is a stand alone webserver.
The easiest way to start XSP is to run it from within the root directory of your application. It will serve requests on port 8080. Place additional assemblies in the bin directory.
Cassini is in fact also a good option - it is the development web server that comes with visual studio (so widely distributed, used and tested) and is also used by the open source ScrewTurnWiki. See wikipedia.
In regards to your "only locally" requirement - a web server will serve any request made to the right port. In order to limit accessibility, you should use a firewall that will block any external requests.
You might consider using WCF to host a service on the local machine that can serve the data without having to host a full blown web server.
If you do this, WCF allows you to expose the service with multiple endpoints and make it available through HTTP, TCP, or Namepipes. Namepipes would restrict traffic to only the local machine.
I have also tried IIS Express. It works great with ASP.NET MVC. Right now it is available only with Web Matrix, but installing web matrix is easy.
Coming back to this question three years later, ServiceStack.NET with self-hosted option seems like a good choice. While it is not ASP.NET MVC directly, it provides a good API and features are on par with ASP.NET MVC/WebAPI (or in some ways better).

Resources