ASP.NET MVC - Quickest way to preview changes to page in MVC app using VS web server - asp.net

I'm an ASP.NET Web Forms developer who has recently switched over to an MVC web app.
I'm having difficulty working out the quickest way to preview code changes when running the MVC web app through the integrated Visual Studio web browser.
In web forms, I can make a change to the codebehind and simply refresh the page and it's all good.
In MVC, I seem to have to close the tab in the browser, return to Visual Studio and press F5, wait for it to build every single dependent project and open up a new tab in the browser to display the page. This is so much slower than how it works in Web Forms it's driving me to distraction.
Am I doing things right? Is there a way to speed this cycle up?

The view pages themselves are compiled dynamically and thus any changes to these can be viewed simply by saving the changes and refreshing the pages in the browser. Changes to code made elsewhere, however, will require a rebuilt after which you can refresh the page.
Pressing F5 will start the web server (if it isn't already started) and then attach a debugger to the process after which it will fire up the web page. The first two steps are very slow, and you should avoid them unless you specifically need to start the web server or debug the application.
So
Changes to view: ctrl+s -> refresh web page (f5)
Changes to code: ctrl+shift+b -> refresh web page (f5)

I used to find setting my project to run via IIS, rather than Cassini, made it a bit quicker. If you've made changes to the code, you'll still have to compile the solution, but at least this way you aren't waiting for Visual Studio to slowly crank itself into gear every time.
Found this article that might provide some clues too:
What are the (dis)advantages of using Cassini instead of IIS?

Related

Auto Build MVC app on after code behind change

In old sweet Web Forms times, when we make change on code behind, once we hit the application, it was compiling on the fly and running new changed code.
For Web Apps and MVC, when I add a new controller or change something on business logic, I have to always build app on VS 2015 manually and go back to browser and test again. But many times I keep forgetting building till I see yellow error screen.
Is there any way to kick build if there is code change and if I hit the website first time like Web Forms? I would not prefer to build on save since I am a ctrl + S freak, and keep pressing that combo on every other second.
To my knowledge Dynamic Compilation is not available in an MVC application because it won't be a "Web Site" project, it will be a "Web Application" project. Only Web Site projects can do dynamic compilation, since with MVC you're routing to actions in the controller my guess is it has to be compiled in advance - unlike ASP.NET where you're routing to a physical file.

Need to debug both asp and silverlight solutions together

I have two solutions, one is asp.net and another one silverlight solution. Both of them are hosted on my local server. What I need is to debug two solutions simultaneously, in asp solution i have page with a code like that
<iframe src="http://localhost/UI_RegInc/UI_RegInc.aspx?UserId=<%=UserId%>"
frameborder="0" height="620" scrolling="no" width="1000" marginheight="0" marginwidth="0">
</iframe>
Here i'm calling UI_RegInc silverlight application, where UI_RegInc.aspx page is calling silverlight application that i want to debug.
What I tried was to start asp application, then in another instance of VS i launch silverlight applicaton, it is UI_RegInc, and in this instance
trying to attach it to iexplorer process with asp application. But getting no positive result. Also tried to attach to webdev process.
A cumbersome explanation, but hope will understand.
Add your ASP.NET and the Silverlight project to a common solution and the Visual Studio debugger will attach to the Silverlight application automatically while debugging the website project. You cannot attach two separate instances of Visual Studio to the same Internet Explorer instance, so you have to add both to the same solution and debug from there.
You can either add the Silverlight project to your existing ASP.NET solution (right click solution, Add -> Existing Project) or create a new solution for times you want to debug both at the same time (create a new blank solution and add the existing projects, same as before).
Here is the process to configure everything step-by-step after that. You can download this source files to the test solution here:
http://www.singulink.com/ClientFiles/StackOverflow/CrossProjectTest.zip
The projects are as follows:
CrossProjectTest - Silverlight 4 project
CrossProjectTest.Web - ASP.NET project that hosts the Silverlight application inside Index.html
IFrameWebApp - ASP.NET project that has an <iframe> pointing to Index.html in the other ASP.NET project
1) In the ASP.NET project that is hosting the Silverlight application, change the settings so it doesn't open a page when debugging and specify a port so that you can always reach it at a known address (which in this case will be http://localhost:18000). You don't want it to open a page because the IFrame ASP.NET project has the actual page you want to show. We still want it to hook the debugger into the web server process though, which is where step #3 will come in.
2) Point the src attribute of your iframe inside the IFrame project at the known address of the page that hosts the silverlight application in the other ASP.NET project, like so:
<iframe width="100%" height="100%" src="http://localhost:18000/Index.html"></iframe>
3) Right click on the solution file, and select Properties. Under "startup project" you will want to select "Multiple startup projects" and set the start action for both of your ASP.NET projects to "Start".
4) Make sure Silverlight debugging is enabled inside BOTH the ASP.NET projects, especially the IFrame project for this particular scenario:
5) Set a breakpoint in your Silverlight application, press F5, and everything should launch. Because you set both ASP.NET projects to start, it will fire up both development web servers but only one internet browser, pointed to the IFrame project. I added a breakpoint in the App Startup of the Silverlight project just to demonstrate it getting hit:
6) Press F5 to continue execution and Silverlight should show up in the IFrame, as can be seen here:
7) Happily place breakpoints in any of the three projects and Visual Studio will debug all of them!
You have to check Silverlight on your Web project that host Silverlighth application.

asp.net compilation has browser issue

I am compiling asp.net 2.0 code. I have IE 8. When I compile application, it open two browser. One browser is blank and other one show web form after a while.
why it happening?
You have 2 web projects in the solution and it's starting both of them up. To avoid this, go to properties on the one you don't want, the Web tab, then change the Start Action to Don't open a page.

ASP.NET javascript debugging does not work in 2 projects

I have 2 asp.net web applications, one of which is the main application and the second one is referencing the first application for like master pages , themes etc, and the main frameset that will point to the second application's webform based on database values (menu generated from database);
All my actual forms are in the second application, but the problem is when I set a breakpoint on the javascript file on my second application, it doesnt go into the breakpoint?
Any advice please? I need to get the debugger working, without having the need to put in the "debugger" keyword in javascript if possible.
My IDE is visual studio 2008 SP 1 and IE 8 as the browser.
Cheers
Do you have the solution set up to start up both projects with debugging when you start the debugger? To set multiple startup projects, right-click on the solution. Choose Set Startup Projects. In the dialog, select multiple startup projects and set the two web sites to start up with debugging when the debugger is started.
For what it's worth, I usually like to debug my javascript in Firefox with Firebug. I much prefer that to the developer tools in IE 8.

Debug .asp pages with visual studio 2005

I'm migrating a website made in classic asp to asp.net, but the asp.net dev server doesn't handle .asp pages.
Is it possible to make it run .asp pages? Maybe a custom httphandler for .asp?
thanks!
Are you running Winxp with IIS installed? If so, here's what I do: hit the asp pages in the browser using your local IIS, and then open the folder where the ASP pages reside as a website project in VS. Go to the Debug menu, choose Attach to Process, and then look for the dllhost.exe process that is running under the IWAM_MACHINENAME user. You also have to make sure the you have setup the virtual directory to allow ASP server-side debugging. After attaching to that process, you can set breakpoints, etc. as usual.
The last time I had to debug asp pages I found it was easier to insert a bunch of Response.Write()'s. If you cant find a way to do it in VS, then this may help.
Unfortunately you will have to use traditional (or arcane!) methods to debug your asp pages in VS2005 (i.e. alert(), response.write() etc.)
Possibly not what you want to hear, but vs2005 doesn't support this. It was re-added into vs2008. Perhaps one of the free vs2008 express edtions might get you out of this hole?
In addition to the answer provided by patmortech I would recommend that if you are testing a mixed tech site you attach to aspnet_wp to debug the .NET portions of the app. This is also true if your app uses third-party ISAPI filters.
The Cassini server is good for pure .NET only.

Resources