Duplicate domain in URL or Domain/AppName - asp.net-mvc-3

I'm sure this is a simple issue, but I have noticed that when I host (shared host on GoDaddy) a website the URL repeats the Application name.
Example, I have http://makedifferences.org, if I go to this its fine, but if I click a link it takes me to http://makedifferences.org/makedifferences/...
It's not just this one site, it's all my sites on GoDaddy and I think it may be the same on my sites hosted elsewhere, but I can't check them rite now.
I'm not using web deploy to deploy it, as my first thought was it had to do IIS. My guess is that it must be a setting in Publish Settings, but I played around with them and couldn't seem to get it to go away.
Any advice would be appreciated.
Thanks,
Garrett
Update
This is apparently not a mvc thing as I check on a site I have hosted at dotnet-host.com and it doesn't have this problem. So I guess it is something with my settings at Godaddy.
I have deleted the folder and setup a virtual folder and this did not fix the problem.
I have multiple site hosting through them and my domain name A record is my dedicated IP for all the sites, then in host's domain management I point the domain name to the folder the site is in.
I think this is the correct way to do this but am not sure.
To restate my problem now that I know a bit more about it, if I type in http://makedifferences.org/Charities/Details/3 the page loads and everything is perfect. But if I click a link on the home page to go there the url is http://makedifferences.org/makedifferences/Charities/Details/3
Thanks why I thought it was a setting in Visual Studio.

There are two things that cause this behavior.
Your Application is installed in a folder instead of root directory for the shared hosting.
Your DNS settings point the domain name to this folder.
I suppose you are hosting multi-websites in shared hosting.
To get rid of this problem, you need to go in the IIS settings and set these folders as virtual directories.....Or create one for each website....And then install your application in that folder.
UPDATE
This is actually not an issue related to GoDaddy shared hosting at all but an issue with hosting an ASP.NET MVC site in a virtual directory. When you use the shared hosting provided by GoDaddy you get a root folder and limitless subfolders, each of which can be its own domain, by way of virtual directory. Unfortunately, MVC’s routing engine produces URLs that will include the virtual directory name appended to the domain name.
For example, let’s say you have a domain named http://www.example.com and your folder/virtual directory name is /File. If you take the MVC template project without making any modifications and upload it to your folder and then go to your url everything will look fine. You will notice the ‘Home’ and ‘About’ tabs at the top right of the page. When you click on the ‘About’ tab, since it is routed to the Home controller’s About action, you would rightly expect the URL to be www.example.com/Home/About. What you will see, though, is that the URL generated by the ActionLink method includes the name of the virtual directory. Therefore, the URL will be www.example.com/File/Home/About.
To get rid of this problem, add the following code to your Web.config’s system.webServer element
<rewrite>
<rules>
<rule name="Remove Virtual Directory">
<match url=".*" />
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
</rewrite>
Solution seeked from HERE
Best of luck :-)

To work in all cases I used rewrite rule:
<rewrite>
<rules>
<rule name="Remove Virtual Directory">
<match url=".*" />
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
</rewrite>
And the function bellow:
protected void Application_BeginRequest()
{
#region Godaddy shared host fix - Detect VDIR in url and remove
//verified that HTTP_X_ORIGINAL_URL keeps the original url (withoud domain) before url rewrite module,
//that way can check if the virtual directory name is at start, and remove it.
if (Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL"))
{
var origUrl = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
var matchVdir = "/" + Myproj.Core.Constants.Environment.HostingVirtualDirectoryName + "/";
if (origUrl.StartsWith(matchVdir))
{
var urlFix = Request.Url.GetLeftPart(UriPartial.Authority) + "/" + origUrl.Remove(0, matchVdir.Length);
Response.RedirectPermanent(urlFix);
}
}
#endregion
}

Related

Rewrite rule 404 issue with site hosted on WPE

We have a tricky setup hosted on WP Engine which has a must-use plugin that uses Laravel.
The goal was to totally eliminate WP from the fetches that the plugin would catch and process.
On my local machine I managed to write such rule for IIS in a few minutes, but eventually needed to install Local WP to be able to come up with a rewrite rule that would work under nginx.
Here is the nginx rule that works within Local WP, that's based on the regular WP permalink rules:
location /api/v2 {
try_files $uri $uri/ /wp-content/mu-plugins/xxx/server/public/api.php$is_args$args;
}
Now, this does not work on our WPE dev site. It obviously loads the correct file, because the 404 screen I get is coming from Laravel, but it seems that everything that goes after /api/v2 got striped or not being included.
A full query would look like this:
/api/v2/admin/members?limit=10
Here's the original rewrite rule I added to IIS:
<rule name="XXX Api" stopProcessing="true">
<match url="^api/v2/(.+)/?$" ignoreCase="false" />
<action type="Rewrite" url="wp-content/mu-plugins/xxx/server/public/api.php" appendQueryString="true" />
</rule>
Can anyone please help me to figure out why the rewrite returns Not Found on WPE, but works on Local WP?
Edit:
Actually, I just dumped the request URi for this particular address.
On Local WP it's the following:
"http://xxx.local/api/v2/frontend/members"
vs. on WP Engine:
"https://xxx.wpengine.com/wp-content/mu-plugins/xxx/server/public/api.php/"
So, it doesn't seem like the rewrite works at all on WPE, it only points to the correct file.

Redirect Rule For IIS Sharepoint Site

We have our Sharepoint 2019 site set up, and everything is running fine. However, when a user clicks the Brand Bar "Sharepoint" in the top left header, it brings them to a broken page. Researched this, and it seems like this link cannot be changed in 2019, as others are having this issue.
https://social.technet.microsoft.com/Forums/en-US/1ef910ec-fb70-443e-bcf4-2d277dc11d2a/sharepoint-2019-on-premise-management-shell-not-working-as-expected?forum=SP2019
What we wanted to do is a redirect, so whenever they went to the broken link, it would just direct them to the real homepage for our sharepoint.
Example -
Broken link is http://servername/my/_layouts/15/sharepoint.aspx
Correct link is https://sharepoint.companyname.com/SitePages/Home.aspx
Here is what I came up with to add to the web.config file, but doesnt seem to be working.
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*_layouts/15/sharepoint.aspx" destination="https://sharepoint.companyname.com/SitePages/Home.aspx" />
</httpRedirect>
</system.webServer>
</configuration>
Any idea on what needs to be done here? Is this even possible? I didn't set up the sharepoint site here so I'm not sure how http://servername/my/_layouts/15/sharepoint.aspx even became the brand bar link.
Thank you!
If you want to redirect from servername/my/_layouts/15/sharepoint.aspx to sharepoint.companyname.com/SitePages/Home.aspx by iis url rewrite, you can try this rule.
<rule name="test6" stopProcessing="true">
<match url="^my/_layouts/15/sharepoint$" />
<action type="Redirect" url="http://sharepoint.companyname.com/SitePages/Home.aspx" />
</rule>
This has been resolved.
Not sure what happened, only thing I did was place the rule on the top most part of the tree in IIS where the server name is. Before I was putting the rule on the actual site in the drop down. I guess this makes sense since the URL I wanted to redirect had the server name in it.

What is the proper way to add rewrite rules in an Azure App Service

I want to add re-write rules to my Azure app service, but if I even try create a web.config with a simple rewrite as shown below, the site returns an HTTP 500.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="test" />
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
What I did is create the web.config from scratch and FTP it into the wwwroot folder for the app service which is where I Ftp'd the rest of my web site files.
I have seen an old conversation about web.config files in Azure, but I'm not even sure if this is in regards to Azure app service - and things change so quickly in Azure that I thought I should ask separately anyways.
I have also seen this link about using web.config transforms. Maybe this is required?
This other link seems to indicate that updating web.config is possible, but their example results in an HTTP 500 for me as well.
I've looked through configuration options in the Azure portal for my app service and nothing seems to jump out at me.
>>”This other link seems to indicate that updating web.config is possible”
Yes, we could update the configuration of Web App by updating Web.config file directly. You could upload a new version of configuration file to wwwroot folder by FTP/WebDeply or any other ways provided by Kudu. Another easy way to edit files in wwwroot folder is using the App Service Editor, you could use it to edit the configuration file.
I can’t reproduce your problem on my side. Following are what I done.
Create a Web App using a Web App Plan with “Shared” SKU.
Create 2 file, a index.html file and a Web.config file. The content in Web.config is same as yours.
Upload these files to wwwroot folder of my web app using FTP.
Open a web browser and input a URL like this “http: // xxx.azurewebsites.net/test”. The web server will return the content of index.html. It proves that the rewrite is working fine.
>>”but their example results in an HTTP 500 for me as well.”
Firstly, please mark sure whether the rewrite is working fine or not. I suggest you view the index.html page directly and check whether the error code(500) comes from index.html page.
Sometimes we provide the wrong syntax for rewrite rule, it will return 500 (URL Rewrite Module Error). Have you enabled Detailed Error Logging and Web Server Logging for your web app. If yes, you could view the detail error message to get more useful information. For how to enable and view diagnostics logging, link below is for your reference.
Enable diagnostics logging for web apps in Azure App Service

How to get IIS Express to serve static content above the root

My home page, which is in my web root, has a relative url that starts with ../../lib/, so ../.. is above the web root.
When I try to serve my site with IIS Express, I get a 404.
How can I get this to work without moving the resources or changing the urls in the html page?
There might be a more direct way of doing this, but this is possible by adding the following to the web.config.
I noticed the 404 url was as if it was at the root, so the match url is at the root. I guess it just ignored the ../.. when interpreting the route.
First I set up a virtual directory on my local IIS to serve up the files above the root. I called it lib and pointed it at the content above the root. The actual path shown here is what I needed and just serves as an example.
<system.webServer>
<rewrite>
<rules>
<rule name="Files Above The Root" stopProcessing="true">
<match url="lib/(.*)" />
<action type="Redirect" url="http://localhost/lib/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm using IIS Express just for debugging and it bears no relationship to how the site works in production. Coloring outside the lines is OK when it's just for debugging. The site build doesn't depend on this at all, and the config doesn't interfere with the site running in an actual environment because no urls are ever going to match this path.

intercepting url rewrite module, prevent rewrite

Is there anything that would cause the url rewrite module in IIS to not fire off? Maybe a site that is in integrated mode or an http handler?
I have tried a few different things to get the rewrite rules to work but nothing. My latest is as such
<rewrite>
<rewriteMaps>
</rewriteMaps>
<rules>
<rule name="rewriterule" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Redirect" url="http://www.google.com" />
</rule>
</rules>
</rewrite>
and it doesn't work at all. I've tried various regex, etc. Its like it doesnt get used.
Seems like you have your answer but here are some other possible things that might cause Rewrite Module not to work :
When you deploy your web site and see this feature not working on
your server, it is highly possible that you misconfigured something
on your server. One of the misconfiguration you might have done could
be setting the overrideModeDefault attribute to Deny for rules under
<sectionGroup name="rewrite"> inside your applicationHost.config
file.
If you are on a shared hosting environment and you see this feature
not working, then ask your provider if they have given you the
permission of configuring this part.
In your development environment, if you run your web site under
Visual Studio Development Sever, you won’t be able to see this
feature working. You need to configure your application to run under
at least IIS Express to see this feature working.
The answer in my case is that you have to be running the site in the same target platform as the url rewrite module. for example, I have x64 version of url rewrite module installed but the site was running under 32bit. Once I setup the site to run under 64bit, the rewrite started working.

Resources