ASP.NET MVC and WebApi project in one solution - asp.net-mvc

I have created solution with MVC and WebAPI empty projects.
The MVC one return SPA page which should communicate with WebApi project.
But when I set MVC as startup the WebApi one do not work.
How to do that?
#Edit:
Of course I want to do that:
localhost:xxxx/MVC/Index
localhost:xxxx/API/someapi

Right-click on the solution in the Solution Explorer and select "Set Startup Projects". In that dialog, set "Multiple Startup Projects" and indicate which projects represent applications you want to start automatically. In this case it would be your two web projects.

In VS.NET Solution Explorer, Right-Click your MVC Project and choose "Set as Startup Project".
For future reference, whatever project name is in bold in Solution Explorer is the startup project.
As David mentioned, your projects will be running on different ports as they should be. By default, VS.NET will use dynamic port assignment, but this behavior can be overridden on the Properties pages of each project.

Related

How to debug Web API through a separate Web project on same machine?

I'm taking over a project from someone who is no longer avaiable to ask how/why their prjoect works.
I have two solutions, one a MVC project and the other a Web API. The MVC project calls the separate API solution to do some validation of data. If I start up the Web API project it runs on localhost:64633. Then I need to start up the MVC project so that I can step through the code and all the way through the Web API.
Thing is that the MVC project runs on localhost:64633 as well so once I have the API running and then try to debug the MVC project I get an error "Unable to start program localhost:64633. An operation is not legal in the current state.".
How can I debug both the MVC project and Web API project at the same time?
Run Your project using local IIS server, follow below steps for that
Right click on project file choose property
Go to Web tab, under the Servers header choose Local IIS
Then click "Create virtual Directory" button
Do above steps to both project. please try now
Note : Run both project with in single solution, automatically debug both project at a time.(Just suggestion only)

Unable to add Razor view to project

I can't add razor view to MVC 5 project in Visual Studio 2017.
There just doesn't seem to be the template
As you can see if I choose Web from template list nothing is visible and all I see is Please choose a project type.
Now this is puzzling as I've seen this related SO post & this where both of them suggest to set project type GUID in .csproj.
I do have it set and it was there (I didn't add anything)
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
Looking at the list of GUIDs it seems that the first GUID suggests that this is ASP.NET MVC 5 project.
I also checked VS2017 installation and I do have web tooling installed
Any clue what I can also try to enable adding web templates to project?
Are you trying to add a new project to a solution or a new item to a project? Its not clear in your question?
Within your project (Solution Explorer), try right click on the Views Folder, choose add, New Item and see if you can find anything there?

Multiple projects in one solution like nopCommerce 3.5

How do I create 2 ASP.NET MVC projects in a single solution, similar to nopCommerce 3.5? The two projects would be:
Web project at http://localhost:15536
Admin project at http://localhost:15536/Admin
In NopCommerce physically there's no two project,
If you go physically you'll find the Nop.Admin project is under the Nop.Web project , and you have to create the second project and you refer to the http://localhost:15536 project in Visual studio and add the second project with add an existing project and you have to implement AreaRegistration to specify your Url in this second project and of corse your dll have to be generated under /bin of the first project.
Best Regards

How to use 2 asp.net projects together

I'm working on a web application with asp.net mvc 4 and I want to do a administration interface,but I want do it in other visual studio's project. So I don't how it works, the routing, how connect to the database from other project. I'd really appreciate any help.
Follow this steps.
Create one solution
Add two projects to the same solution
Point the web.config of the two projects to the same database
It doesn't have to be so complicated with routing, because each project belong to a different site and a different environment.
In my opinion you should create just want project and define a new area for the administration

How do I coordinate settings between my ASP.NET MVC 3 app and SpecFlow?

So I have a VS 2010 solution containing one ASP.NET MVC 3 project and one SpecFlow project (with NUnit as test runner) to test the former. When testing under SpecFlow (by running the SpecFlow project), I'd like to change a parameter in the MVC application's ConfigurationManager.AppSettings dictionary, to make it connect to a test database. This change does not seem to affect the running app however, so I guess the test and the app do not share state.
How can I share this application setting between the MVC app project and the SpecFlow project, so they use the same database?
Edit:
I found that the problem wasn't really one of sharing settings between projects (MVC and SpecFlow), but rather between two processes. The reason is that I test MVC via WatiN, which means that the development server, running in a process of its own, is being exercised by the tests. As such the premise of my original question was wrong from the onset, and I consider Jason's answer valid given the original premise.
In your test project (SpecFlow) create a new app.config (unless it's already there) and add the appSettings section to that, with your test database connection string. IIRC the website will hopefully pick up the connection string from the appSettings of the test project, rather then the website.

Resources