Issue running MVC project while editing a View - asp.net-mvc

To put it simple, whenever i run (debug) my MVC project while focusing a View (in the editor window) on Visual Studio 2012, the web page shown on the browser is the View itself rather than the actual landing page.
For example:
If my usual landing page is the following:
http://localhost:53338/
Then if i'm focusing the 'Add' View and I Run my project, it sends me here:
http://localhost:53338/Views/Products/Add.cshtml
Any idea how to 'fix' this?
Thanks in advance

Your web debug configurations are set to run the "Current Page".
Here are the steps on how to solve it:
Go to the project's Properties (Right-Click on the project -> Click on Properties).
Go to the Web tab.
Select the Start URL radio button and leave the address text-box blank.
In the Project URL type: http://localhost:[portNumber]/
Good luck

Related

Visual Studio MVC debug launch route

When I hit debug (shift+F5) I want the launch route to be
localhost:XXXX/Controller/Action
Instead of
localhost:XXXX/Views/Controller/Action.cshtml
How do I do that?
By default, Visual Studio will often automatically attempt to go to the current page that is selected when debugging your application (thus attempting to access your current .cshtml page).
Setting a Default Start Action
If you want to set a particular Action or URL to be launched when running your application, you can do so through the following steps :
Right-click your Project within the Solution Explorer.
Choose Properties.
Select the Web tab on the left-hand side.
Under the Start Page section, define the Specific Page you would like to default to when the application is launched.
Save your changes.
Assuming your using Visual Studio 2015 or 2013: Project Properties -> Web (tab) -> check Start Url and enter in the desired URL.

Set Startup Project in VS 2012 Web Application

Is there an easy way to set the web application as the startup project and not have it change automatically? In the solution explorer I right click on the project and hit "Set as Startup Project" but if I end debugging and try to start again, VS tries to set whatever page I'm working on as the startup project. Am I missing something or am I just being picky?
Thanks in advance.
Set web project as startup:
Right click the solution, under common properties > startup project, ensure the correct startup project is selected:
To set a specific page within the project:
Right click on the project, select 'Web' then under 'Start Action' you can set exactly what page you would like to start. If you want to load a specific page, select the 'Start URL' option and enter a URL. For example in MVC use /Controller/Action
set as start page in vs2012
Right click the Project
Select Properties
Click on Web
Select Specified Page
Specifies the controller/action you want to always start. Example: Home/Index
Enjoy!

"Browse With..." button missing in VS 2012

I upgraded my MVC 3 project to MVC 4 according to the instructions here:
http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806
Everything works fine, except that I don't have the new Browse with.. button appearing in the toolbar, nor can I activate this option in the project's context menu.
I should note that the button appears properly in new MVC4 projects (i.e. those created from scratch instead of upgraded).
How can I fix this?
Update:
See workaround in my answer below.
Right click on the top menu and add in the 'Standard' Toolbar.
If it's still not there you can right click -> Customize, select the 'Commands' tab. Select Toolbar: Standard then hit 'Reset All' (this will only reset the 'Standard' toolbar).
Try just adding an '.aspx' web forms file to your project. You should get the 'Browse with ...' option in the context menu when right clicking on that file in the Solution Explorer. You should be able to change the browser that way. Then you can delete the '.aspx' file once you have chosen your browser. I have had to do this in the past.
I was able to fix it by creating a new .sln and adding my projects to it.

"Browse with..." option not available on ASP.Net MVC Project

I'm sure this is a simple misunderstanding but I'm trying to change the default browser in Visual Studio 2010 from Firefox (my machine's default) to IE so that VS will stop debugging when the window closes.
Based on ScottGu's post on the subject, I'm expecting a "Browse with..." option when I right-click on an aspx page in my MVC app; but there's no such option.
Also (possibly unrelated), when trying to launch the ASP.Net Configuration, the Cassini Development Server starts, but no browser instance launches. Starting to get very frustrated!
Asp.net MVC doesn't let you do this
You can only see "Browse with..." when you right click on the Default.aspx on app's root. Otherwise it's just not there.
This menu option obviously isn't stupid and doesn't let you browse a particular view, because it's not up to the browser to request a particular view, but up to a controller that may display some (or any) view... So Visual studio doesn't give you this option on your views.
I suppose it would be best if you've changed your default browser on your development machine.
In ASP.NET MVC 1 projects, you have to right click Default.aspx to get the "Browse with..." option.
However, ASP.NET MVC 2 projects do not have a Default.aspx. The best way to change your default browser is to create a standard ASP.NET project and set the default browser using that.
I'm building an MVC 2 project and encountered this issue. I just created a Default.aspx web form in the root folder, used the Browse With... menu it exposed to set my browser for this particular project to IE, then deleted the Default.aspx. Kind of a pain, but you only (should need to) do it once.
You can add an app_offline.html file to your MVC3 app. This is useful, because if you rename it to app_offline.htm and deploy it, it will cause IIS to deny all requests to the app (and will return the content of the app_offline.htm(l) file).
If you have one of these, you can right-click it to get the browse with option. In case you want to test out with different browsers & window sizes from VS, without a plugin.

How can I make visual studio open the controller Im currently on be default when debugging?

Right now it always goes to default.aspx that subsequently opens the default controller but I would like to go directly to the controller I am editing when I hit the debug button.
Right click on the Web Site in Visual studio and select Property Pages. The Start Options section gives you flexibility as to which page loads first. You can choose and set the Start URL option to something like http://localhost:1324/Home/Index to force debugging sessions to default to the HomeController's Index action.
This requires two things to be true:
1234 is a static port used by the Cassini web server when debugging your pages (you can change this behavior by pressing F4 on the web site's project and setting the Use dynamic ports setting to false and the Port number field to a port of your choosing.
The Web Site automatically starts up when you run the application from Visual Studio. Make sure it is by selecting the Property context menu item from the Solution's right click menu and editing the Common Properties -> Startup Project settings.
Alternatively, you can use the Use Current Page setting of the Start Options dialog. Developer beware though, as I'm not sure how MVC-aware this option is.

Resources