Help with mvc deploy on asp site - c#

i have this problem... i have an ASP.NET MVC application locally and i have in one server another application in asp, i need to add the mvc application to the asp application. So i have "http://www.aspApp.com/mvcApp" but i cant work with the mvc application, when i call for example /Controller.aspx/Action, it throws a 404 error, and the address that i see in firebug for the get is "http://www.aspApp.com/Controller.aspx/Action", but this should be "http://www.aspApp.com/mvcApp/Controller.aspx/Action" i think... i try to change the post and get's in the mvc application to /mvcApp/Controller.aspx/Action instead /Controller.aspx/Action but it doesn't work at all, if in the explorer i put "http://www.aspApp.com/mvcApp/Controller.aspx/Action" it throws the 404 to. The IIS is 6.0 and i think i have the correct configuration for mvc.
I hope you can helpme, thanks!

Setup your routes like this,
// Classic URL mapping for IIS 6.0
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);

You need to put the web.config inside your "mvcApp" virtual directory - so the mvc app will know the application root is at that directory instead of at the website root.

I fix it! The problem was on the iis configuration, the check "Verify that file exist" was checked and i uncheck and fix the problem.

Related

Host WebApi and C# site under the same domain

I have a website made in C# (http://my.site/), and now i have a Web API project that i want to merge to that domain and listen on http://my.site/api. They are 2 separate projects in VS2013.
I tried uploading Web API to /api/ subfolder in the server and map a MVC route to it (WebApi route in WebApiConfig.cs still routeTemplate: "api/{controller}/{id}"), expecting the default (Home) MVC controller to respond in /api/. The MVC route (in WebAPI's MVC routing):
routes.MapRoute(
name: "Default",
url: "{controller}", //Also api/{controller}
defaults: new { controller = "Home", action = "Get", id = UrlParameter.Optional }
);
But i get "Server Error 404" when accessing http://my.site/api/ / http://my.site/api/home etc. I don't understand the nature of this error (most likely settings in the C# website in root folder), but one would think IIS would serve the default app inside the /api/ folder.
So i want to know if adding WebApiConfig.Register(GlobalConfiguration.Configuration); to Global.asax (Application_Start()) and adding WebApiConfig.cs to App_Start folder of the C# project (and using the respective namespaces) will solve the issue. This seem too simple to be true so i doubt it will work, so i need someone to point me in the correct direction, or i will commit the sin of going back to asmx.
If not, how can i have C# website and a WebAPI on same domain?
You are wanting to run two separate dlls (each with their own routing rules) within the same bin folder on your server. That could definitely cause some conflicts in routing on your site. A proper way to do this would be to host your api project on a separate server and use a sub-domain, such as http://api.my.site/. That way you ensure that your C# site (http://my.site/)would have access to the api (http://api.my.site/). And your dlls, including routing rules, would remain separate.

.Net MVC 3 403.14 error

I'm creating an asp.net MVC3 demo application. I have attached the application with this thread. I'm facing a HTTP Error 403.14 - Forbidden issue when trying to run the application. The issue occurs only in a specific scenario. i.e. in the RegisterRoutes method in the global.asax
has only the below code then the issue occurs.
routes.MapRoute(
"Process1", // Route name
"Process/List" // URL with parameters
);
If we have the above code with default route the application works fine without any issues. The issue occurs when i have this particular code alone in the register routes method.
I tried the solutions given in this link but it did not work.
I assume the issue with that code. If yes then please let me know what causes the issue. I use windows 8.1 & the iis is 8.5.
The code can be found here
You have removed the default route and defined the following route:
routes.MapRoute(
"Process1", // Route name
"Process/List" // URL with parameters
);
In this declaration it is not clear which controller and which action should be
executed. You should explicitly state them:
routes.MapRoute(
"Process1", // Route name
"Process/List", // URL with parameters
new { controller = "MyController", action = "MyAction" }
);
and then make sure that you are making the request to the proper url that you have defined:
http://localhost:1619/Process/List
because you don't have any route configured that is capable of handling the http://localhost:1619/ request that you seem to have made in your screenshot.
Of course having such route is completely constraining. The only controller action you could ever have in your MVC application is the one defined as such in the route config. This is fine in a SPA application where you have a single entry point serving the SPA and a separate ASP.NET Web API but in a real ASP.NET MVC application with multiple controllers and actions it is not going to work. So you probably want to keep the default route in this case and do not experiment in this area.
You must have a default root in your global.asax file to make it work. add one default and then you can add this route.

Is there something special about a MVC controller called properties?

After trying to work this out for ages, thinking about routing conflict and more - I started a separate project from the start.
It looks like an MVC controller called "properties" always returns a 403.14 forbidden message when you try to access the root site (http://site/properties) - however, other pages work (http://site/properties/index).
It works fine as a controller in an area, but, I just can't create it in the main site.
I was wondering if anyone knows why and what the best way round this is?
In addtion to DavidG's answer.
When you publish the project the compiled build does not have a Properties folder. To solve the issue while developing locally you can set RouteExistingFiles to true so ASP.NET routing handles all requests.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.RouteExistingFiles = true;
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
The issue is that your project already contains a folder called Properties which is mainly used for the AssemblyInfo.cs file but has other stuff in there too. The engine used to resolve what files to send to the client prioritises files and folders over routing. so the URL http://site/properties is trying to server content from there, which is ultimately blocked anyway.

Static Html page is not working after hosting in ASP.NET MVC

In my MVC project, There is a Default.html file in root folder and route this file as a default route.
routes.MapRoute(
name: "",
url: "Default.html"
//,
//defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
It's working fine when I access it like http://localhost:51353/Default.html
I host (include this static file) this project in my web server. But it's showing error:
Is there any additional configuration needed to do this ?
If you want to host a static HTML page within an ASP.net MVC project then you need to configure your routing configuration in MVC to ignore requests for those pages.
It worked locally because you may have set it as start page in Visual Studio. For this to work you need to tell MVC to ignore the route if its for the HTML page or ASPX page. Find your routing configuration section, it’s in RouteConfig.cs under the App_Start folder. Use the IgnoreRoute() method to tell Routing to ignore the specific paths.
routes.IgnoreRoute("Default.html"); //ignore the specific HTML page
Now MVC ignores a request to load the Default.html page and leaves IIS to handle the resource.
As per the MVC Routing you cannot map static files to the routing table, because when MVC Routing Machanism provides direct access to physically exist static files.

ASP.net MVC virtual path

I would like to add a virtual path to my asp.net application. In visual studio there is a setting virtual path I'd like to put a version number as the part of the url of my application.
It was like http://localhost:53278/{controller}/{action}
I would like to add an extension like this
http://localhost:53278/0.0.0.1/{controller}/{action}
Somewhere I need to configure in my asp.net mvc 3 application ?
Thanks
Are you trying to do this dynamically?
Areas can be used if that isn't desired, but in the end it represents a different route entry. That route entry can be dynamically added or hard coded.
When adding routes you can do something like
// used System.Reflection.Assembly.GetExecutingAssembly().GetName().Version to get the version then build the string you want
context.MapRoute(
"Versioned_default",
"<YOURVERSIONSTRING>/{controller}/{action}/{id}",
new { action = "Index", controller = "Home", id = UrlParameter.Optional }
);
It's generally not a good idea to include periods in the url, other than for extensions. 0-0-0-1 would work. In visual studio, right click on the MVC project in solution explorer (the project, not the solution) and on the web page, if you're using the default development server, then just change the virtual path and save. Done.
If you're using IIS, you have to type in the path and click Create Virtual Path.

Categories

Resources