Rails console alternative for ASP.NET MVC? - ruby-on-rails

The biggest thing I miss from Rails is the super handy console.
Let's say you need to call a certain function on the server that will update the database. In Rails, you just launch the console and call it.
In ASP.NET MVC I have to call it in a controller, rebuild the whole solution, transfer the compiled dll to the server, go to the page that has to call the function (it has to be protected of course), and it's done.
So is there an alternative?
Thank you

I don't know of anything like console for asp.net. But I do know of an alternative to what you're doing because I used to do similar things all the time.
You don't have to upload the newly compiled solution to the server. All you have to do is change your connection string from development to production. Then just run it locally and your production database will be updated.
To organize things a little better I had an admin page where I could do various database management tasks. I'd just create button links on the page for whatever it was I needed to do and all the actions were placed in an admin controller. I set the permissions on that controller so that only an admin could access the actions.
On a side note, why are you going from rails to asp.net MVC? I did asp.net for a few years and rails for a few months now. I find I prefer rails these days a lot more.
Edit: (if you need something quick and dirty)
add a button on one of your existing pages linked to a controller action
point your connection string to the production database
run locally and click the button
Afterwards, remove or comment out the code you just ran.

There is no console per-se built in in ASP.NET (although there is one in Visual Studio) but if your models are independent of the rest of the system you should be able to call them from a command line application (or even a Visual Studio unit test) really quickly.

LINQPad makes an excellent equivalent to Rails Console.. Instructions here:
https://stackoverflow.com/a/9403457/1029644

Related

How to debug MVC web app with rest api controller backend? [duplicate]

In VS 2012, I am attempting to create an MVC 4 web application with jQuery calls to a Web API project. (Other devs will be consuming the API with our current, native app, and probably adding to the API in the future.) So I have one project that is the Web API, and another project that is the MVC 4 website. I can only set one of them to run, and they use localhost:xxxxx.
How do I debug changes to both? For example, let's say I add a new API path /api/customer/get and then a new jQuery ajax call to that path and do something with the resulting JSON. I've changed code in both projects and want to follow it end-to-end; how do I launch both? How do I debug both?
Just to be clear, the MVC app isn't making server-side calls to the API, I'm using MVC mostly to be able to easily use bundling, minification, and (hopefully) pre-compiled Handlebars templates in .NET; the API calls are coming from jQuery. As I am still relatively new to these technologies, alternate suggestions are welcome.
Thank you in advance.
I had the same problem and have found a solution from here:
forums.asp.net
The fix is to do the following:
In your solution file, click properties go to the Startup project node (if it is not already selected)
Next select Multiple startup projects. Select your website and your webservice and in the Action column make sure both of them have "Start" selected.
Now when you debug your website and put a break point in your webservice, it should hit the break point.
Coming late to the party but in case anyone else is looking for a solution, this is what was best for me: Set the Api project up to be the starting project (I needed to limit to one startup so that I could flip between browsers more easily). After firing up the service project, right click on the web/ui project and select debug, start new instance. You'll have both running and you'll seamlessly step from web to api.
I had a similar problem with my web api project. My solution consisted of an angular front end with 2 web api projects on the backend. One web api project handled "authorization" and the other handled "resources". I used the following tutorial by Taiseer Joudeh as a starting point:
http://bitoftech.net/2014/09/24/decouple-owin-authorization-server-resource-server-oauth-2-0-web-api/
Breakpoints worked on the "authorization server"... but not on the "resource server". I compared the packages from the two projects to see what was different. Once I added "Microsoft.AspNet.WebApi.Cors" to the "resource server" project, the breakpoints starting working.

following iterative and agile in asp.net MVC

ok, i know there are a lot of posts online that specify how to do iterations with MVC.
my question is slightly different. when i used to do iterations using WebForms, i was creating one thing only and finishing that one thing till the end which was including the deployment on production.
for example, i was creating a webpage and deploying it, then i create the second page and deploy it. so .dll files were added to my bin folder while the previous dlls remain untouched. at the other hand, when i was making a change latter on, there was this one file that needed to be replaced on production.
now here is the question, how can i acheive the same thing in mvc? beause it just doesn't deploy each page into an individual dll. each time that i add something i have to redeploy the application dll which is not really wise! i played around with deployment options in visual studio but no luck!
There is nothing preventing you from putting controllers and other code in separate assemblies and dropping them in an existing application. Like any ASP.NET based application an MVC application will automatically restart if you add or modify any file in the bin folder or modify web.config.
If you're using Razor you can use RazorGenerator to generate code for your views and compile them into the same assembly.
You may need to write some additional logic though to get routes, model binders etc. wired up correctly.
For a more structures approach to compose the application of separate modules, you may want to look into portable areas. This is an extension to ASP.NET MVC that allows you to package the entire module (including views, css, js etc.) into a single assembly.
First thing, you have to work on the title of the post, it does not match the content of the post.
In asp.net mvc u can choose to deploy only what changed. I.e. If you only changed the .cshtml file, then you can just replace it with the file in production. However if you change any controller class (C#/Vb code), then you will have to upload the web project dll file too so that this new changes are available in the production env

Learning how to mix Telerik AJAX controls with MVC -- Seeing garbage characters?

I am attempting to find a place to start debugging this issue at.
I do not experience this issue if I create a new, MVC2 project, but I am trying to integrate into our companies existing MVC solution.
I am adding a ScriptManager to the MasterPage. Something like this:
<telerik:RadScriptManager ID="ScriptManager1" runat="server" EnableTheming="True" EnablePageMethods="True">
</telerik:RadScriptManager>
Here is what I see when I try and run.
I'm extremely new to MVC and unsure of where/how to start debugging this. I have a hunch it has something to do with either the Global ASAX or Web Config file, but without any more information I'm not sure where to begin poking around.
Has anyone seen this before?
partial-answer: it seems that moving the script manager inside of the closing tag resolved this issue, but the second I tried to add a control to my View I am back to looking at garbage. Plus, it doesn't match what I had to do in the default app. Wondering why.
Some asp.net controls simply won't work in MVC because they rely on features that MVC doesn't support, such as viewstate. I'm not sure if the Telerik ajax controls are in this boat or not, but you can't assume any control will work. Generally, the more complex the control, the less likely it will work.
I notice that you have it working in a default project, but perhaps that project has no real data or doesn't use the same features that your production app uses.

Running a console app from the Umbraco backend

I have been charged with making a C# console application to do a daily migration of an Umbraco site from a developer site to a live site. The console application works like a charm, but the customer wants a button in the Umbraco backend where they could force the migration instead of waiting for the daily execution.
My question is this:
How would one go about making such a button. Is it possible to run a console application from the Umbraco backend or would I have to make it into a user control? Any help would be appreciated, and if you need more information just write a comment :)
I'm not aware of a way to run a console application from the Umbraco interface.
Possible solution:
Can the console application simply run every 10 minutes and check a value in the database? If the value is true, then do the migration and reset the value. This could be a date as well.
Then in Umbraco simply make a dashboard .aspx page with a button that says "Go Live" and that sets the flag in the DB to true.
Make sense?
This is my idea. I am not sure whether its correct or not . Please go through it.
In umbraco we can create a macro by using Asp.Net user controls. So in that macro put a button and in that button click i think we can execute the console application.

ASP.NET MVC for Ruby on Rails developers?

Long time lurker, first time poster. I'm a self-taught hacker that learned Ruby on Rails to start. At work I've been allowed to work on a web app--the only catch is I have to use ASP.NET. This technology choice is mandated, as much as I'd prefer to use Rails.
There's dozens of "Rails for .NET/PHP/Java Developers" books and blog posts but I haven't found any going the opposite direction, from Rails to .NET.
Could someone please give me an overview of how a typical Rails app would translate over to ASP.NET MVC? I'll research the details of the IDE, C#/VBscript, etc. But what are the possible equivalents to:
Generators
Gems/Plugins
Databases
Migrations
Routes
Models (ORMs)
Controllers (InheritedResources)
Views (layouts, templates, partials)
Rails Console
Test Units/Specs
etc. anything else I'm forgetting
I assume a lot of the Rails niceties I take for granted like route-based helper methods, and simple macro association declarations will not be possible. :(
Thank you so much!
I think what you'll find in the .Net world is that you have a lot of choices to make. Rails is nice because it provides all of that stuff in one place, but developing for .Net you'll have to piece together a solution of your own.
Generators - There are various code generation facilities, but each one is for a different piece. Eg, you can get MyGeneration that will generate code based on a database.
Gems/Plugins - No uniting system for this; Components can be found on the web and you would download either the source or the .dll, then you would add a reference in your project to the assembly (.dll).
Databases - you can connect to pretty much anything; You'll probably find the most guidance for an MS SQL Server.
Migrations - I don't know of a direct method for this in the .net world; I usually write SQL code in SQL and run scripts on the server manually as part of deployment.
Routes - ASP.Net MVC includes routes, look in the global.asax.cs file that gets generated when you create a project for example.
Models (ORMs) - ORMs for .Net are all over the place. Included as part of .Net are things like Linq-to-sql and the Entity Framework. Outside of MS you can find many, but I'd probably recommend NHibernate.
Controllers - Built in to .Net MVC; You get to write the code.
Views - Built in to .Net MVC; Once again you get to write them. MasterPages allow you to get the same general layout on all your pages(including common header/footer, etc), Web Controls (.ascx files) allow you to do a partial view.
Rails Console - I don't know exactly what this provides (I'm a .net developer interested in learning Rails, but haven't spent much time yet); Visual Studio lets you debug applications, step through code, etc. I don't think there are any consoles available to test code outside of just writing the code, compiling, and running it.
Test Units/Specs - There are a few test frameworks for .Net (MS has a framework included, NUnit is one alternative). For specs and such, probably google around for Behavior Driven Design and see what exists.
There are a couple of .NET ports of RoR migrations. I have used migratordotnet and FluentMigrator. Both work as expected but I prefer FluentMigrator. It is more full-featured (e.g. can create indexes) and I like the fluent style.
LINQPad is your equivalent to Rails Console.. see here:
https://stackoverflow.com/a/9403457/1029644
You should download Visual Studio 2008 Express, and download ASP.NET MVC 1.0 (I wouldn't download ASP.NET MVC 2.0 yet because it's only in RC. Wait until it hits 2.0 final).
You can also check out the Nerddinner walkthrough. It's very helpful when learning ASP.NET MVC.
Generators
Do you mean code generators? Ew.
Gems/Plugins
If you want functionality, you can either build it or see if a JQuery plugin exists for it.
Databases
The Database is accessed through your model.
Migrations
?
Routes
Routing is handled by the framework, and you can add routes in the Global.asax.cs file.
Models (ORMs)
Models are indeed still called 'Models', and in ASP.NET MVC, if you use LINQ-To-SQL, the model is generated for you when you drag your database tables in. You can use the Repository pattern to access the database model.
Controllers (InheritedResources)
Controllers are still called controllers.
Views (layouts, templates, partials)
There are different types of View Engines, but the one provided with ASP.NET MVC should do well at first.
Rails Console
I'm guessing you mean the IDE/Debugger? You can build and debug an ASP.NET MVC app inside of Visual Studio.
Test Units/Specs
You can use NUnit, or you can use MSUnit. MSUnit is already integrated with Visual Studio, but NUnit can be.

Resources