IIS Sub-application root - asp.net-mvc

I have an existing Web Application hosted in IIS which an ASP.NET MVC application. Now I want to add a sub application,But when I deploy, some relative paths like "~/" or "/" will be imported back to my parent application.
Example:
The URL of the parent application is https://www.example.com/
Then my sub application is https://www.example.com/subApp/
When I try to click on the "subApp/test" page, it should be directed to https://www.example.com/subApp/test, but he still leads back to https://www.example.com/test.
How can I solve it?
Can it be modified through Web.Config instead of going to each page one by one

check your URL rewriting module. if it is there?

Related

How change default url (remove subdirectory) for MVC application

Just deployed ASP.NET MVC5 web application to IIS 10. To do this, under "default website", I created a new application ("Add application"). I had to put in an alias so I put in "xyz".
So, now the public url is similar to http://xyz.mysite.com/xyz .... but I want it to be only http://xyz.mysite.com (remove 'xyz' subdirectory).
How can I do this?
The problem is that my ajax calls are failing because of the subdirectory.
You can do either of the following:
Option 1:
Add Website in your IIS (instead of Add Application) and use the SNI feature. All relative path will be from root (/) level.
or
Option 2:
Modify your AJAX calls to use #Url.Action("actionName", "controllerName") so your URLs will be generated properly based on relative path. I suspect you are hardcoding actionNames to "/controllerName/actionName" which uses root as your relative path.

URL Routes In IIS7 MVC 5 (Single Paged Application)

After publishing a MVC5 web application of mine to my IIS server (Individual User Accounts), it would seem that the URL is accessed incorrectly.
During debug, it would be e.g http://localhost:1234/api/Account/UserInfo?=XXXXX
The debug works just fine. The only issue kicks in after I've published it via my IIS7 server.
After publishing and using Google Chrome's console, it would appear that the page is requesting for a resource at mydomainname.com/api/Account/UserInfo?=XXXX instead of mydomainname.com/WEBAPPLICATIONNAME/api/Account/UserInfo?=XXXX.
My best guess is to modify the URLs in /Scripts/app/app.datamodel.js but it would just cause more parsing problems.
I've searched around and can't seem to find any related problems. I hope someone here will be able to lend a hand.
Look like you are using relative path like "/api/Account/UserInfo". Instead i'll recommend you to use #Url.Content("/api/Account/UserInfo"). This will solve your problem
Explanation
In local system when we run application in WebDev server it never have sub folder (like WEBAPPLICATIONNAME) therefore you relative path work correctly. but when you host your application in IIS under Default website in another new website /Virtual folder (like 'WEBAPPLICATIONNAME') then "/api/Account/UserInfo" fall back to Default Website because for '/' in starting. #Url.Content or #Url.Action make sure to add virtual directory name, hence changing your path to "/WEBAPPLICATIONNAME/api/Account/UserInfo" in IIS.

Running MVC application on IIS without domain

My application contains lots of links to the root ("/login/dologin"). When I'm running the application under a domain, there's no problem.
Right now I'm moving to a new server, and I can't test my application. My application sits in "localhost/md", I need the link to go to "localhost/md/login/dologin". Instead, it goes to "localhost/login/dologin", and, ofcourse, the resource cannot be found.
What do I need to configure on my IIS to make this works without domain?
Thanks.
It's just a guess, since you haven't posted any of your configuration.
In your authentication element in the web.config, do you have the route to the login page specified as /login/dologin? could you try ~/login/dologin
The second option, should give you a relative path from the home of the virtual directory application, rather than going to the root of the 'site'
For referencing files (e.g. javascript & css) you could do #Url.Content("~/path/to/file.js")
EDIT: Based on additional comments
in Layout.cshtml...
var SITE_ROOT = '#Url.Content("~/")'
then in your JS file use SITE_ROOT as a prefix in your routes
var url = SITE_ROOT + "Home/Index";

asp.net mvc using HREF in application running on IIS

There is a partial view representing pager control (very similar to this) for blog content. Code generates HTML with references and href like, "/Blog/Posts/Page/1", "/Blog/Posts/Page/2" etc.
It worked absolutely fine on Cassini, but after I switched to IIS problems appeared.
IIS application running in virtual folder, so URL is
http://localhost/tracky
and blog area located,
http://localhost/tracky/blog
As I press on pager button, I recieve 404, because the URL would be
http://localhost/blog/page/3
Instead of
http://localhost/tracky/blog/page/3
My question is, how to handle such situation? how to change code generation to provide correct URL? how to make it work same - as root applicaton or application in virtual folder?
Source code is here
You need to generate your urls either by using ActionLink in your view, or using an UrlHelper in your href as follows: <a href="<%=Url.Content("~/blog/page/3")%>" ..>bla</a>. This will generate Urls that are adjusted accoring to your application root.
You should be using the following:
UrlHelper.GenerateContentUrl("~/Blog/Posts/Page/1");
The ~ allows the url to be resolved relative to the application path and should produce correct results in both cassini and IIS.

Asp.Net MVC on Subdomain, standard MVC app gives 404's

I am trying to deploy my MVC app on a subdomain, unfortunately I get 404 errors.
I tried to find out if it's MVC itself that can't handle being hosted on a subdomain.
I uploaded the standard bare MVC webapp that you get when you start a new project. The index page loads, but all the other pages that require actual routing based on the url do all give 404's.
What do I need to change to be able to use MVC on a subdomain.
(it's all setup on a IIS 7.5 server as a seperate website)
I had this problem with a shared hosting provider. I had to get them to change the Application Pool to "Integrated Mode" instead of "Classic" mode in iis7 for it to work. Not sure why, haven't really looked into IIS7 that much
Is this a shared host where the subdomain is resolved via URL rewriting to point to a sub folder?
MVC doesn't care what the domain name is. I've used it with a couple different subdomains, but they were not on the type of host that would be rewritting to a sub folder.

Resources