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.
Related
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.
I have a mvc project my url is hostname/xxxx and i have folder name called xxxx.
If i enter this url hostname/xxxx means it directly go to my folder but i want it go to my code controller
If you don't have these in your IIS handler mappings then you need to install mvc on the server
Add the following to your routing file to tell it to use the route rather than browse the directory
routes.RouteExistingFiles = true;
This means that if you have a route of myHost/myFolder and a file of myHost/myFolder/myFile.ext, then the URL myHost/myFolder will be handled by MVC routing and the URL myHost/myFolder/myFile.ext will navigate to the file.
is it possible in MVC to setup a site where it would have one set of controllers but dynamically build the site based on a url that looked like this:
www.a.com/sitename/index
Each sitename would have it's own configuration, data, and look and feel.
Well, you could simply deploy the same MVC (or any) web application to separate virtual directories, each with their own configuration (and CSS files, etc.).
Alternatively, you could change the default route table to include {tenant} (which is what this is often called) as part of the path, and pick that up in your controllers.
I have a web application that I'm using a custom route to route http://domain/MyMVCSite/MyPage.ASP to route to a controller/action of my choosing.
I'm not TOO familiar with custom routing, but as it stands, this is my custom route:
routes.MapRoute(
"Page",
"MyPage.ASP",
new { controller = "KTASP", action = "KTASP", id = "" }
);
As I said, this routes:
http://{domain}/MyMVCSite/MyPage.ASP
I would like for it to route:
http://{domain}/MyPage.ASP
Is this possible? How would I tweak the custom route?
My MVC site is being deployed as a virtual directory of a website on IIS6.
This isn't possible without IIS configuration to rewrite the requests for "http://{domain}/MyPage.ASP" to go to your virtual directory.
Currently, your web application will never get considered, because that page is not within the virtual directory it is mapped to in IIS. You need to either have routes (and a web app) at the root of the web site, or use URL rewriting to forward it to your vdir.
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.