Which namespace should I use for my Asp.NET MVC 4 beta Filters? - asp.net-mvc-4

I am trying to implement a global exception handler in Asp.NET MVC 4 beta. As I understand it I am supposed to implement an IExceptionFilter and add that to the filters collection. However I was unable to make it work when using the System.Web.Mvc.IExceptionFilter. Am I supposed to use that one, or is the System.Web.Http.Filters.IExceptionFilter (and related classes) the ones I should be using?
Asking another way:
Should I be adding filters to the GlobalConfiguration.Configuration.Filters or GlobalFilters.Filters?

System.Web.Http namespace completely belongs to ASP.NET Web API framework, not ASP.NET MVC.
As for the registration point, you need to add them into GlobalFilters.Filters collection.

So after getting some pointers from #tugberk, I realize my mistake. I was basically asking for the wrong thing. What I wanted was to be able to add filters for an ASP.NET Web API service, not add them for an mvc application.
I made this error thinking they were one and the same. I guess I must have read som of what was said about moving these things together the wrong way.
In any case. I should be using the System.Web.Http namespace for my case, which means adding to the GlobalConfiguration.Configuration.Filters collection.
I found a rather nice weblog showing a basic implementation of some of what I want to accomplish. Maybe it can help somebody else.

Related

Should someone programming using VB Forms use MVC pattern

I am refactoring some code and am working with another programmer. I suggested refactoring the code to follow the MVC pattern to remove all the plumbing from the forms code and put them into seperate classes such as a controller and model class for database. He disagreed with me saying that VB is not meant for MVC and that we should put the code into DLL's. I agree with DLL's but put the MVC into the DLL's is my opinion. Have I got the wrong idea ?
It is a desktop application? because in that case it would be more useful a pattern of MVVC. In any case, I recommend that you seek information from Domain Driven Development (DDD). Here's an article from a practical example =>http://www.codeproject.com/Articles/768664/Introduction-to-ASP-NET-Boilerplate

How do I use JavaScriptSerializer in ASP.NET 5?

I am porting my project to DNX-Core 5.0 and trying to get work but I cannot find the JavaScriptSerializer and AppSettingReader classes. I know the System.Web is removed and so please anyone help me to find the alternative of using them.
Is there any Nuget available to include them?
The ASP.Net 5 team dropped the JavaScriptSerializer in favor of the widely used Newtonsoft.Json package, but they did provide a JsonOutputFormatter and a JsonInputFormatter for use with MVC to be able to return objects more directly.
For the AppSettingReader you'll want to look at the new ASP.Net 5 Configuration Model. This has been detailed in a few blog posts while it's being built. These posts only detail how to load out individual fields, but the tests in the Options Model show that you can bind directly to an object.

asp.net mvc 4 localization resource path too long

I've created a class library in which I store my resource files for my asp.net mvc4 localization. I've been following the same folder structure as my Views.
I'm ending up having to reference strings such as:
#Resource.QuoteArea.Quote.Auto.DriverInfo
That is very long and tedious to type. Plus it makes my Views hard to read. Is there a better (neater) way for doing localization in mvc 4 ? Perhaps using a third-party library ? I already use mvccontrib for my model localization, so that's sorted. However for non-model related things, I'm facing the aforementioned issue.
You can change the resource namespace in the resource properties, to make it shorter. This blog post was very helpful for me, and will be for you to.
http://adamyan.blogspot.co.uk/2010/02/aspnet-mvc-2-localization-complete.html

ruby on rails - create a simple html page

I need some assistance in creating a simple html page and locate it in the server.
Since I couldnt find it in the doc I tried to put a index2.html file in the /public library and when I tried to get receive it using
http://127.0.0.1:3000/index2.html
or
http://127.0.0.1:3000/public/index2.html
and receiver
ActionController::RoutingError (No route matches [GET] "/public/index2.html"):
how do I get the html from the server
how di I make it the default.
Thanks.
EDIT : thanks for your answers. I am looking for the simplest way to work. in many tutorials it says you can put it in the public folder and thats it. This will same me useless controllers.
You can do that in several ways : the more obvious would be to have an action in one of your controller (or a new one, whatever) that does nothing (except render the view), and add a route to it. There is other ways to achieve this too, with more adapted tools. I never used any of them, so might want to google it (static page rails), but I know one of them is a gem called High Voltage. Hope this serves you well.
I think you might have mis-understood Rails...
I have never used it but I think I can probably help you with your answer. Rails is the most popular MVC framework for the language Ruby, hence 'Ruby on Rails'. Here is a link to the MVC framework this may help you understand it:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
With the MVC framework you can't 'get' a file directly through the URL. You have to get it through the routing engine. Usually you do this through a Controller which renders a view, typically, from a model.
It's difficult to explain if you don't understand how the MVC framework works but once you have an understanding you should be able to develop web applications very rapidly.
Have a look here for creating your first rails app:
http://guides.rubyonrails.org/getting_started.html

Writting My lightweight MVC framework

I have planned to write my own light weight MVC for PHP, that will be used as base for my sites I develop. I have no problem with PHP, OOP, et al. I have trouble on how to actually load Models In controllers and use them amd loading Controller values into Views. In short, I don't know how M-V-C interact behind the scenes.
Any tutorial (concentrating on that) or any contribution is welcomed!
Thanks!
ASP.NET MVC is open source: http://aspnet.codeplex.com/releases/view/58781
Edit: consider this: I believe you are trying to reinvent the wheel, thinking that those MVC framework out there are heavy and packed with uncessary features (acording to your double use of the word lightweigth). In my experience, I always ended up coding those extra "features" because a framework is required to evolve. Loading models In controllers, using them and loading controller values into views is just the begining. If you want to get started eventually, it would be a better investment to write some helper classes and methods: a popular pattern in the MVC world. Unless you are writing a MVC framework from scratch for fun and I am totally wrong (you said you needed a base to use for your sites ).
Best of luck!
Codeigniter is an open source MVC framework of php.
http://codeigniter.com/user_guide/overview/appflow.html
The major in MVC is first of all your controller class initiated and then calls view.
After google and check how other MVC works I decided to take this route. I redirect all my requests with .htaccess to index.php. Then there I define base paths. After all the definitions I include the core.php which in turn includes all core files to my mvc framework. Then in the same file I create Instances of Registry and router and the game starts from here!
Internals are a bit complex now but that is what I ended with!