Define ashx file in MVC doesn't work - asp.net-mvc

I define a ashx file in MVC4 project in content folder so it doesn't work ?!!
So i have several questions?
1- Can we define ashx file in MVC or it isn't possible?
2-If we can define how can we do that?
Best regards

You can definitely use an .ashx file in MVC. An MVC app is an ASP.NET Web app. You should add the .ashx in the root folder (not the content folder), or in a normal subfolder, as you would in an ordinary ASP.NET web project.

Related

In MVC what extension should the view file names have?

I have been given a sample MVC project that contains views with extension .aspx
however when I create a new MVC project using the VS2013 ASP.Net wizard the views have extension .cshtml
Are there 2 kinds of MVC project?
Views in MVC refer to either .cshtml files in C# or .vbhtml files in Visual Basic.
.aspx files are webform files and are not views-- this was the initial approach ASP.NET took to make webform development more similar to desktop application development. These pages are generally included in the route list as actual files, whereas MVC uses controller routes that aren't based on existing files (i.e., the url path doesn't match the file and directory structure like traditional html does), which ultimately serve the views. .aspx files can also have code-behind files to separate the html/aspx markup from the .NET code; those files will have either a .aspx.cs or .aspx.vb extension on them. In an MVC app, these files are also likely to have designer files.
One set of files for an aspx file named MyPage may have the following files:
MyPage.aspx
MyPage.aspx.cs or MyPage.aspx.vb
MyPage.aspx.designer.cs or MyPage.aspx.designer.vb
The files in #3 may be hidden until you select 'show all files' in the project, or may not exist at all in a traditional 'web site' project type. I think you have to upgrade to a 'web application project (Wap)' project type before you can integrate MVC, though I may be wrong. All WAP projects should have these .aspx.designer.xx files.
In MVC what extension should the view file names have?
.cshtml unless you have a reason not to use the Razor view engine with C#.
Are there 2 kinds of MVC project?
The relevant answer is that there are many more than 2 different view engines. Razor was introduce in 2010. The Razor view engine is what comes out of the box in the Visual Studio MVC templates. See ASP.NET MVC View Engine Comparison for more info on more obscure view engines that work with ASP.NET MVC.

Uploading and reading of files from the root directory in asp.net mvc

I need to verify the ownership of my website by placing a specific file in the root directory. How can I do this in asp.net mvc ? What I'm trying to achieve is the URL:
http://somehost/MyWebsite/OwnershipFile.txt
I have tried creating an Action in the Home Controller but that doesn't work because the link contains the suffix .txt.
If my understanding is correct, asp.net mvc's razor is an extension-less view engine. That being the case, how can I achieve what I'm after ?

javascriptmvc folder structure with asp.net mvc

It seems to me the first biggest hurdle of fitting javascriptmvc into asp.net mvc, is the folder structure. Has anyone adapted the asp.net mvc folder structure to serve up content files from the folder structure javascriptmvc expects?
using routes.IgnoreRoute("javascriptmvc-3.0.5/{*pathInfo}"); in your route definitions things should work as expected.

Two web.configs?

ASP.Net MVC applications has two web.configs. One in the root folder and one in the Views folder. Why?
From Pro ASP.NET MVC 2 book:
/Views/Web.config:
This is not your application’s main
Web.config file. It just contains a
directive instructing the web server
not to serve any *.aspx files under
/Views (because they should be
rendered by a controller, not invoked
directly like classic Web Forms *.aspx
files). This file also contains
configuration needed to make the
standard ASP.NET ASPX page compiler
work properly with ASP.NET MVC view
syntax.
One reason is to simplify your views and your pages. You can put the compilation or even the masterPageFile declaration from your views in this web.config, for example.
Phil Haack did a great post on this -> http://haacked.com/archive/2009/08/04/views-on-a-diet.aspx

Deploying asp.net mvc web site

I have asp.net mvc web site. When i want to change some code in controller i need to build all the site and upload it to the server. Is there some merhods when i need just copy controller file by ftp?
The .cs files that contain the controllers are compiled into dll files, so at the very least you have to upload a new set of dlls.
The views defined in the .aspx files are a different story. You can make changes in the .aspx files without rebuilding the entire site.

Resources