Using Cassini with a virtual path that contains dots - asp.net-mvc

I am working on an existing project in ASP.NET witch is based in a folder that contains dots
http://localhost/My.Awesome.WebClient/
This setup works fine using the integrated Visual Studio Develompent Server, but fails when I add MVC content and try to access it (Error 404 Resource not found).
http://msdn.microsoft.com/en-us/library/ee941656.aspx seems to explain the issue:
If you create a file system Web site in Visual Studio 2010 and the Web site is in a folder that contains a dot (.) in the folder name, URL routing will not work reliably. An HTTP 404 error is returned from some virtual paths. This occurs because Visual Studio 2010 launches the Visual Studio Development Server (Cassini) using an incorrect path for the root virtual directory.
However, the project is a Web Project, not a Web Site, and it only failed when I started using MVC.
The problem can be easily reproduced:
File - New - Project - ASP.NET MVC 3 Web Application
Edit project settings, Web: Use Visual Studio Development Server
Set the virtual path to something that contains a dot
Try to run the site
Is there a way to get this to work, besides using IIS instead of Cassini?
Edit:
I did find a workaround just now. It does not really work in a deployment scenario, but it may help in finding a solution:
in my Global.asax.cs file:
routes.MapRoute(
"Default", // Route name
// Notice that I added the virtual path here
"My.Awesome.WebClient/{controller}/{action}/{id}", // URL with parameters
new { action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
// This is also new
routes.MapRoute(
"Root", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Using this workaround, my MVC-Sites work, but only with the following url:
http://localhost/My.Awesome.WebClient/My.Awesome.WebClient/

If you don't get an answer to this question (personally, I'm not aware of any way around this), I would recommend using "IIS Express", which is available as a free download. It can be installed on development machines and you can control a lot of server settings with your web.config file, which is fairly unobtrusive.
You can download it here:
http://www.microsoft.com/download/en/details.aspx?id=1038
I use IIS Express exclusively now; Cassini has always lacked features and IIS Express avoids me having to configure IIS for each web application.

Related

my localhost IIS display me my project files

I try to launch or browse my asp.Net mvc project on IIS, and he gives an error 403- forbidden, I solved this problem with enable the Directory Browsing, but after that he displays me my folders of the project.
The error
It's because of no default page in your directory refer below article
https://www.c-sharpcorner.com/UploadFile/francissvk/set-default-page-for-a-website-in-iis421/
If you having MVC application then you need to set default route and make sure you have MVC framework installed on the server
'routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters*
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);'
Do you have the correct default documents set in IIS?
Open IIS (Windows key+R and type inetmgr)
Select the Default Documents option
Enter the default page name in the order you want IIS to check (index.html index.php index.py etc)
Disable Directory browsing :)
Now when the root of a folder is accessed without a direct page, it will check all the default names you have specified and display the one that it sees first.
See this link:
https://tecadmin.net/set-default-document-in-iis/
Did you get 403.14? I think your problem is IIS asp.net extension haven't been installed from "Add role and feature" or turn windows features on or off.
So no handler would help to handle the MVC routing request.
https://learn.microsoft.com/en-us/iis/application-frameworks/scenario-build-an-aspnet-website-on-iis/configuring-step-1-install-iis-and-asp-net-modules
Once you enable the asp.net module, this issue should be fixed. MVC don't depend on either default document or directory browsing.
I also notice that both .release and .debug file are displayed in the root folder. So you just copy the whole project files to your IIS root folder right?
It is suggested to only publish release file to the root folder with VS web deployment tool.
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis

IIS 6.1 shows directory listing instead of MVC 3 app

I have just finished development in ASP.NET MVC application and I try to deploy it to a web server. The problem is I only see the content of directory, not the start page. Here is the visual explanation:
Things I did are publishing my MVC site, create a new folder in test server, I create a web site and copy files of publication to test server path.
my .NET Framework version is 4.5.2. MVC version is 4.
Any help is appreciated.
Edit 1:
In the comment below there is a recommandation of seeing "IIS 6.0 suddenly shows directory listing instead of MVC 3 app".(Link: IIS 6.0 suddenly shows directory listing instead of MVC 3 app) None of them solves my problem.
Edit 2:
Here is the content of the RouteConfig file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I have solved the problem and I want to share the solution with you.
I have done everything that described at the links, but I could not solve.
The first server's operating system I have been trying to deploy is Windows Server 2008 R2 Enterprise, and it does not contain any MVC applications, it only contains web forms applications.
The successful deploy has been made in Windows Server 2012 R2 and there are many MVC applications inside. The program ran successfully there. I presume some modules shall be installed in application server.
Hope this helps.

MVC 5 in VS2012

I have installed ASP.NET and Web Tools 2013.1 for Visual Studio 2012 which has the MVC 5 templates for Visual Studio 2012. In Project Templates I am able to find the "ASP.NET MVC5 Empty Project" however after creating the Project, if I try to open the same project in the Internet Explorer by Pressing Ctrl+F5 it gives an error saying,
Server Error in '/' Application.
But When I create a MVC 4 Web Application and try to run it the Application works fine and shows the default page of the MVC 4 App.
Is there any other configuration needed to be done on the Visual Studio 2012 to make it run?
An Empty application is just that. Empty. There is no default page. It's an empty project that you have to create the content for.
Microsoft did not supply a default application template for MVC5 in VS2012. VS2013 does have a default template though.
Since it is an empty template it doesn't have a landing page and hence it was throwing the error
Server Error in '/' Application.
if you append the Controller name and view name just like below
localhost:port/[Controller]/[View]
It will show the contents of view.
you can try either edit your routing.config file, or change your url. Usually it will default to index.
This is an example of a route you can maybe add in as a class, if you do not have one already. This controller just means that it defaults to the Home controller, at the action called index.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
I hope this somewhat helps .

MVC2 Website hosted on IIS7 shows directory listing not the Home/Index

I am trying to host a MVC2 website to IIS.
Steps I have followed:
Create a Website in IIS ( define directory defined physical path and app pool)
Published code from visual studio to the physical path.
But when I tried to browse my site it was giving me error
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory.
So, I enabled Directory Browsing feature, Now it only shows directory listing.
What I have tried?
Added wildcard script map for aspnet_isapi.dll
enabled HTTP Redirection
and some other things that I have found on some answers related to this question but nothing worked for me.
My routing configurations are
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
Here are the things you might check:
If your application is using ASP.NET 4 ensure that this is registered in IIS. The following command should register it using the aspnet_regiis.exe tool: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis -
ir (adapt the paths with the proper version of the framework if necessary).
Ensure that the application pool which is configured for the website is using Integrated pipeline mode.
have you found a solution?
I've been facing the same issue for hours. Here is my strange story.
I was configuring a fresh win srv 2008 R2 with IIS installed through role (7.5....) and Added the same components I have in my dev environment's IIS.
I thought that my system had got .net fw 4.0 because I've been able to crate asp.net 4.0 app pools, maybe because I had already had the 4.5 installed. I had also checked the asp.net installed versions on IIS through aspnet_regiis.exe -lv and my ASP.NET v.4.0.... was magically there in both 32 and 64 bit versions.
but...
I noticed something strange watching at the Default Web Site structure: I had only the aspnet_client\system_web\2_0_50707 folder. So the 4.0.... folder was missing.
My solution.
I've uninstalled .net 4.5 from the server, then installed the v.4.0 downloading the package from microsoft. Then I've registered my aspnet 4.0 version using the aspnet_regiis -i present in its folder (%windir%\Microsoft.NET\Framework64\v4.0.30319).
After reinstalling my mvc3/razor web app, everything worked fine, even without installing mvc3 components on the server.
Morale, ensure that you have the fw version of your choice really installed in the system and configured in iis (aspnet).
Hope this helps.
Ciao.

mixed MVC routing for MVC app under web forms app

I have an instance of BlogEngine.net installed at the root of my hosted server. I wanted to play with ASP.Net MVC to write a small app and installed that app under a folder off the root.
I am able to see the http://example.com/testApp/ but the the routed pages like http://example.com/testApp/edit are giving 404's.
I have searched around and I'm just not clear what is needed to get the routing right. Do I need to set something in BlogEngine's web.config or do I need to be doing something in my applications settings?
The host is WinHost.com and it is IIS7
Edit/Update
So I understand that the http://example.com/testApp gets served because there is a default.aspx under that directory and that the routed pages don't get served because they don't have physical aspx's. The /edit gets routed to the edit view just fine when I launch it under Visual Studio.
I am guessing that the BlogEngine.net's global.asax is trying to map these pages to the BlogEngine world and not routing them to my testApp.
If that is the case then my question is how do I get BlogEngine to forward the requests to my testApp? I was hoping that I was missing something simple in the web.config because if I have to add stuff to BlogEngine's global.asax to do routing then won't I need to rebuild BlogEngine?
Based on the information I found in the MVC tutorial, I have discovered why my routing wasn't working.
My request processing mode on the hosted server was configured to use the Classic .NET AppPool not Integrated mode. To get it to work in classic mode you need to either modify the route table to use file extensions or create a wild card script map.
I was able to keep BlogEngine working using integrated mode so all that I needed to resolve this issue was to change the mode.
Hope this helps someone...
Do you have a Edit.aspx file existing in your application for your testApp controller? The way the default route works is:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
So by default, when you access Home/Index, ASP.NET MVC looks for Index.aspx
In your case, your routing consists of (I just made this up):
routes.MapRoute(
"CustomRoute", // Route name
"{controller}/{action}/{id}", // URL with parameters, id is optional.
new { controller = "testApp", action = "Edit", id = "" } // Parameter defaults
);
Where you are trying to use Edit.aspx
Inside of your Global.asax file is where all your custom routing exists, have you touched that file at all or no? The rule of thumb that I have heard about is that you want to write all the custom routing first prior to the default.
EDIT:
I also stumbled across this, might be helpful
There are four sections in the configuration file that are relevant to routing: the system.web.httpModules section, the system.web.httpHandlers section, the system.webserver.modules section, and the system.webserver.handlers section. Be careful not to delete these sections because without these sections routing will no longer work.
Taking from here
Good luck, hope this helps.

Resources