How To Prepare The Controllers To Use Session But Be Testable
Aug 26, 2010
How to prepare the ASP.NET MVC Controllers to use Session and at the same time be testable, so in essence not use Session but rather use some Session abstraction? I am using Ninject so your examples could be based on that.
The problem is that the Session object is not available at all times in the controllers (like in ctor's) but I need to store something to the Session at application start (the global.asax.cs also does not have access to the Session).
I have the domain name and space and also prepared my website on visual studio. now i want to know how to make it ready, so that i can copy it the hosting server. means what is the prerequisite for hosting? and then how to publish it?
I have an asp.net application that I currently deploy to 4 different environments on the client's servers. At the moment we deploy by copying over individual assemblies and content files but the whole process is time consuming and error prone. Basically I'd like a method of preparing the application for deployment that will give me a folder containing the application (no source code etc). No IIS changes are required. It would be good if I could specify different webconfigs for different environments.
I've looked at msbuild, msdeploy, etc and I'm not even sure which is the right tool for the job. I'm tempted to go with a batch file that copies only certain file extensions but I'm sure there must be a better way of doing this.
I ve completed a web application and now i want to prepare functionality and technical documentation for the same. But i ve never done such documentations. Can someone provide how to prepare such documentations.
I have a select query which is executing well. Now, I want to add one more field to that query. That field is not in the current query table, It is in the another table.
How do I join those two tables and get that field value in the existing select query.?
Everything was good before I bumped into the problem when declarative binding (SelectedValue='<# Bind("SvcCluster_Id") >') produced the error, because value has not been found in the list. So i moved binding to the code:
protected void frmConfigEdit_DataBound(Object sender, System.EventArgs e) { if (frmConfigEdit.CurrentMode == FormViewMode.Edit) { var svcCluster_id = DataBinder.Eval(frmConfigEdit.DataItem, "SvcCluster_id"); var ddlCluster = (DropDownList)frmConfigEdit.FindControl("ddlCluster"); if (svcCluster_id != null && ddlCluster.Items.FindByValue(svcCluster_id.ToString()) != null) { ddlCluster.SelectedValue = svcCluster_id.ToString(); } } }
But now seems like this happens later than ObjectDataSource tries to access frmConfigEdit$ddlCluster...
How to manage this?
I wouldn't like to move everything to the code (I mean creating Control parameters, etc)
p.s. Oops, actually it works ok for DataBound event! Sorry.
i'm in a project with a service layer (WCF), a proxy layer that are between this service layer and the "controllers". Every controller should call this proxy layer to get data, and instead return a model to be rendered, returns a bigger entity that i've to convert using Linq to a more little model. Then pass it to the view.
Do you think is a good idea that this conversion be done by the controller? In my opinion the controller is not the responsable to shape the incoming object from the proxy layer. This object should be returned by the proxy layer and the controller should pass it to the view directly.
I want to test that when my form data is posted back to my controllers that the data annotations and the model binding is going to do its job and give the correct model state. After googling for a while I can't find a really good tutorial or article that shows how to do this.
Can anyone point me in the right direction? What is the best practice in this area? I have read that I may need to use moq and MVCContrib but I have not read a tutorial that makes me shout, "Yes, this is the right way to do it!"
I'm starting a new ASP.NET MVC project, and I decided to put my controllers in a different assembly. Evertyhing works fine, but I have hit a problem: I created a new area in my MVC Project, called Administration. I have an AdminController Class in my seperate assembly which is supposed to return views from my Admin area, but everytime it tries to return a view, it looks for it in the wrong place (~/Admin/SomeView.cshtml Instead of ~/Administration/Admin/SomeView.cshtml) How can I tell the controller to look for views in the wanted area?
I am wanting to create a path somewhat like this: /Administration/News and have it forward to a News controller instead of it being the action.How would I go about this?
I was wondering what the major differences are between controllers and webservices. I understand webservices can receive postbacks via ajax while controllers cannot. Also, when you put a webservice in a MVC site, what file structure do you use to store it? Just create a single services folder?
Basically what the title says. I created a new MVC application. I'm trying to add new pages to the site, but anytime I do I get the following error:Server Error in '/' Application.The resource cannot be found.Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
namespace MyAppMVC.Controllers { public class ProductsController : Controlle{ public ActionResult Index() [code]...
I'm currently migrating a WebForms app over to MVC. One problem I have is that some users will probably have a page like www.mysite.com/login.aspx bookmarked (or maybe some other .aspx page). Currently this will throw an InvalidOperationException stating that the controller 'login.aspx' could not be found. Is there any way I can handle this so that it redirects the user to another page?
I know I can implement Application_Error in the Global.asax file, but I'd rather not redirect on any InvalidOperationException, just when it's an invalid controller.
I would like to have a project that contains all of my Controller logic. I'm not concerned with using Areas, as these are still maintained within the same project. Consider this scenario: I have multiple sites/apps that require the exact same interaction in regards to a particular area, say CRUD ops on a user account. I do not want to create all of the controller logic for one site/app, recreate it again for the next, and make sure that I keep all maintenance to each in sync. I would prefer to keep the controllers in a separate project and reference them from the appropriate site.
I know someone will say that the controller logic is a lot of times specific to the application (as I've read elsewhere), but let's just say that it is guaranteed to be the same. I want to focus on the "how" and not the "why". So far, I've created a class library project with the appropriate references for accessing System.Web.Mvc. How do I proceed with the routing configuration for this? Is this idea even possible? I read a few older articles that were written when Areas were first being introduced that said to create separate projects for them. Is this idea similar to that?
I am developing a restful web api using asp.net mvc and trying to extend the MVCWEBAPI project on codeplex that i took from here - http://code.msdn.microsoft.com/MvcWebAPII have added a folder nested within API folder inside the Controllers folder.This path does not work - (nested folder Security)http://localhost/API/Security/Authentication/LoginAlthoug, this path works - (not nested)http://localhost/API/Media/GetMediaThe folder structure is Controllers ->APIWithin API folder I added a Security folder and then added AuthenticationController under it.To make the routing work, I updated global.asax.csBelow is the required code.
public static void RegisterRoutes(RouteCollection routes) { var map = new NameValueCollection();
I mean parameters of methods of controllers. For example, I have a View, which has :1. One radiobutton Yes / No (table inside DB has bit field)2. dropdownlist with int values (table has int too)3. Textbox (Firstname for example)I can create a method:
Does it make sense to do error handling and logging inside actions methods or handle the OnException method inside the controllers. One way means writing try/catches in all the action methods even when there is nothing to be done to recover from the error. Handling this at the controller level would allow logging and redirection to an error handler page without writing try/catches inside all the action methods.
Which method makes the most sense? Here is example code of try/catches in an action method.
[HttpPost] public ActionResult Delete(int id) {[code]...
For applications that need to have fastly different view layers, and I would like to still use the idea of the controller. I would ideally like to but the controllers in a Class Lib. and then have only the Views in a MVC Web Application. Taking the model out in this way works well, but I can't find a nice way to split the views and controllers.
I'm using the release 1 candidate from a few weeks ago and am loading my controllers from the spring.net context. I notice that my factory which couldn't be simpler keeps being called for a controller called "css". I'm using the Razor template engine. Does mvc or razor create any behind the scenes controllers that I don't know about?