MVC :: Handling Unknown Controllers?

Nov 1, 2010

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.

View 5 Replies


Similar Messages:

C# - Error Handling In Controllers With MVC?

May 4, 2010

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]...

View 1 Replies

Sub Areas To Group The Controllers?

Feb 17, 2011

Does the current MvcRouteHandler support something similar to Monorail's concept of an controller area? a way to group the controllers.

View 1 Replies

MVC Controllers Vs Proxy Layer?

Nov 25, 2010

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.

View 1 Replies

MVC :: Use Controllers To Get Data And Post?

Sep 12, 2010

I wounder if there are samples how to create Restful serivece withmvc. Or I can use MY controllers to get data and post data?

View 2 Replies

How To Unit Test Mvc 2.0 Controllers The Right Way

Jan 9, 2011

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!"

View 1 Replies

How To Use Areas With Controllers From A Different Assembly

Jan 29, 2011

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?

View 1 Replies

MVC :: Want To Create Two Controllers/Paths?

Sep 16, 2010

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?

View 3 Replies

MVC :: Difference Between Controllers And Webservices?

Aug 12, 2010

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?

View 4 Replies

Can't Get New Controllers Or Views To Work In .Net MVC

Apr 19, 2010

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]...

View 3 Replies

MVC :: External Assembly For Controllers

Aug 24, 2010

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?

View 2 Replies

MVC :: Subfolders Within Controllers Folder?

Feb 4, 2011

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();

[code]...

View 2 Replies

MVC :: Correct Way For Creating Controllers?

Jan 27, 2010

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:

[Code]....

View 5 Replies

MVC :: Splitting The Views And Controllers?

Jan 20, 2010

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.

View 7 Replies

MVC :: Navigate Between Controllers Using ActionLink?

Jan 14, 2010

[Code]....

Navigate between controllers using ActionLink in mvc2

View 2 Replies

C# - Controllers Action, Do Have To HttpContextBase?

Apr 10, 2010

From within my controllers action, do I have access to httpcontextbase?I have a method that takes httpcontextbase as a parameter.

View 1 Replies

MVC :: Copy The Fields Without Controllers?

Feb 18, 2011

How does this step in the MVC Views ?Without sending to Controllers

[Code]....

[Code]....

View 5 Replies

C# - Unknown Server Tag 'cc1:AsyncFileUpload'?

Feb 1, 2010

I've recently downloaded Ajax Control Toolkit to use with my ASP.NET web app.I added the AsyncFileUpload control to a web form but when I try to run the application,I get an error :

"Unknown server tag 'cc1:AsyncFileUpload'."

I have this in the ".aspx" page :

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" ?TagPrefix="cc1" %>

View 2 Replies

MVC :: Loading Controllers From WebService Context

Dec 30, 2010

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?

View 2 Replies

MVC :: Synonyms For Controllers (Custom Routing)?

Jul 18, 2010

I have an ASP.NET 4 MVC2 multi-language application and I need the same HomeController to response ДОМОЙ as well.Our application has 12 Controllers and should support 9 different languages.The optimal solution would be to override some FindControllerByName & FindViewByName, but I can't find such functions.
Do any of you guys know how can I achieve such a behavior?

View 4 Replies

MVC :: Can't Debug The Action Methods Of The Controllers

Mar 8, 2011

I'm currently using asp.net mvc 3 on vs 2010, i can't debug the action methods of the controllers (if its a ajax call/request).

View 6 Replies

Mvc 2 - How To Get The First Part Of The URL Parameters And Pass It To Controllers

Mar 29, 2011

I'm building a site that has a number of language versions. currently I use session variable to manage the country code for different language version

but today the client specifically requires to put the country code in the url right behind the domain name so the site url will be like these examples

uk version: [URL]

usa version: [URL]

I defined the default route to

[URL]

but I'm not sure how to get the first segment of the url in the controllers?

View 1 Replies

Is It Necessary - Shared View For Navigation Between Controllers

Mar 16, 2011

I'm very new to ASP.NET MVC and this is probably a really obvious thing...Basically, I can't access the "Forum" view which I had created inside "Home" folder (because I need a link to Forum on my main homepage.). I was wondering if it's okay to just move the Forum view into the Shared folder?

Is this somehow very bad practice? It seems like I have strong coupling now, because on the one hand the forum view gets called inside HomeController, and on the other hand it will pretty much always be used with ForumController from now on. So that might be unnecessary/wrong somehow?

edit: If I do this, the URLs change in a weird way, there must be a better solution right?

First when I click on forum link on main page, I'm at: /Home/Forum. I look at the forum, everything is fine.

Now I click on "Post a topic", and after the roundtrip I'm at /Forum/PostTopic.

View 1 Replies

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).

View 4 Replies

Rewriting The URL For A Controllers Action Method?

Nov 22, 2010

I have a controller called Person and it has a post method called NameSearch.

This method returns RedirectToAction("Index"), or View("SearchResults"), or View("Details"). The url i get for all 3 possibilities are [URL] How would i change this to rewrite the urls to [URL], [URL] for View("SearchResults"), and [URL].

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved