Asp.NET MVC in subfolder - asp.net-mvc

i have searched here, googling (with bing;)) and try all the things i have found but i
dont get it running.
I have a subfolder created on my webspace at discountasp.net like "MySite". Then i
made a virtual directory with the control panel. I published the Site with Visual
Studio to the path
http://blablabla.com/MySite/. My Domain is pointed to this path too.
It looks good but the links like /Home/About/ becomes /MySite/Home/About/ and thats
(of course) doesnt work.
How can i change that ? I think its an routing issue.
Please help me.

To create your URLs you should use
#Url.Action(actionName, controllerName)
This will use the routes you specified and it will create correct URLs.
You can also use
#Html.ActionLink(linkText, actionName, controllerName)
To include images and stylesheets use
#Url.Content("~/Content/...")

I got it. Pointing my Domain directly on the subfolder and defining a
Outbound rewrite rule on iis solves my problem.

Related

Remapping URLS in web.config

I need to add a term to the URL's within a sub-directory of a website I'm working on to boost/enhance SEO. For example, http://www.domain.com/shop/product/ should go to http://www.domain.com/shop/product-SEO/ instead. I need to set this up in web.config and looked at examples on here but couldn't find anything similar. Any help?
The feature you are looking for is called URL Rewriting.
You should have a look at the following link, it will provide everything you need:
http://msdn.microsoft.com/en-us/library/ms972974.aspx

How to create an alias path on local IIS?

Unfortunately searching the web didn't make me any smarter. I have a web application running under my local IIS 7.5: http://localhost/myWebpage/
Now I'd like to create an alias path pointing to the same application, something like http://localhost/myWebpageAlias/ (the application will change it's layout according to the different address).
How can I achieve this?
Thx for any tipps
sl3dg3
Try creating a new virtual directory under "Default Web Site" (or whatever site is serving 'localhost'), then point it to the same directory:
Though it is the too late answer. But to alias path, you can use the IIS URL Rewrite module to create a rule which maps one URL to another. Visit here for details description.

How do I serve static files from mvc without using content folder?

I want to be able to have a folder which allows regular access like the \content folder except that it holds a ClickOnce application. I can't seem to be able to achieve this using Mvc, but I'd like to have this folder accessible without Mvc seeing it as a controller action.
I tried using routes.Ignore(theUrl), but this seemed to have no effect.
There are two ways you can do this. The first is where you are currently going, which is to satisfy it with routing. You should be able to use the following to ignore the intended route:
routes.IgnoreRoute("...")
However, this might not be the right approach from a security stand point. I would recommend you define an explicit action to download your click-once exe. Have a look at this q/a as an example of using the FileContentResult class.
The reason for this is that you can control security for that file without having to open up access levels to other directories.
Edit: If this is for an entire directory, you can still follow this same approach.
Set up the folder as a virtual folder in the website on IIS. then you can set the url in the code to point to the machine serving the request and to the virtual folder on the web server.

Wordpress with ASP.NET MVC

I have Wordpress in a subfolder in my site named blog.
When I goto the url of my site /blog/ I get the error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
This use to show the default theme and an empty blog.
I think it may be a routing problem with MVC?
Does anyone know how to correctly set this up or how the routes should be configured?
Try putting this in your RegisterRoutes handler in global.asax:
routes.IgnoreRoute("blog/{*subfolder}");
It might also work simply with blog/*, but I am not quite sure.

Can I serve images in ASP.NET MVC application from Views directory

I have some pages designed by someone else as simple HTML that I need to dump into my MVC application.
Not surprisingly the images are stored in a local /images directory.
I'd like to be able to serve the images up from the Views directory where the main view pages are.
I'd rather do this than make it its own virtual directory, but I'm not sure if this is really easy or possible. In the future i forsee having to add 'mvc' components (such as RenderPartial or Html extension code) into the pages so I'd prefer the pages to be part of my application instead of just tagging along in their own virtual directory.
Main path:
http://example.com/microsite/
Images path:
http://example.com/microsite/images
I'd want microsite/images to map to Views/Microsite/images if possible.
Or if theres a way to create a 'pseudo' virtual directory in the application I'd rather do that than rely on having to set up the virtual directory from within IIS - but I don't think thats possible.
I tried using something like this, but that doesnt work of course because this isnt actually mapping, but just an ignoring of a route:
routes.IgnoreRoute("microsite/images/{*pathInfo}");
Using <img src="<%=Url.Content("~/my/path/to/images/picture.png")%> should resolve no matter what the actual location of the image. Instead of "~/Content/Images", you'll point to "~/Views/Products/Images/product1.png", or something close to that.
There is no need to modify routes with this implementation.
It sounds like you might benifit from a MVC 2 feature called "Areas". Phil Haack posted on this new feature.

Resources