Referencing relative (parent) path with sudomain - asp.net

I have a website with several subdomains that direct the user into a subfolder on my site. Inside each subfolder is a Default.aspx file which does some processing and then redirects the user to "../Default.aspx".
This works fine if you type the full URL to that page. If you try to access it through the subdomain, the ".." parent is not being parsed correctly, and just concatenates the subfolder path into the main path and I get a page not found.
The root path of my application is www.domain.com/root.
The subdomain points to subdomain.domain.com/root/subfolder
When I navigate to subdomain.domain.com, I get this error:
"404 - /root/subfolder/root/Default.aspx not found"
All I want is for subdomain.domain.com to redirect the user up one folder level to www.domain.com/root/Default.aspx
Can anyone help? Is this a feature/restriction of using a shared hosting provider - the subdomains are restricted to the folder where they are pointed?

Your description is a bit confusing, since you mix local paths and URLs together. Am I right that you are trying to do: Page at subdomain.domain.com/root/subfolder/Default.aspx redirects to www.domain.com/root/Default.aspx?
That means you want to do 2 things:
Redirect from sub-domain subdomain to sub-domain www, and
Navigate to a file one folder up.
Both things you can do in a single HTTP redirect. For this, use the Response.Redirect method, and make sure that in the URL you use the www sub-domain, and the correct absolute path to the page you want to show.
Response.Redirect("http://www.domain.com/root/Default.aspx");
Update
Or, redirect to a URL relative to the current page, in the same domain.
Response.Redirect( Page.ResolveClientUrl( "../Default.aspx" ) );
Update 2
Or, use the Host HTTP header to distinguish on subdomains and switch programatically in your shared codebase.

The answer is to point all the subdomains to the same folder (the main code base) and then in the Master file, switch based on the http header. If they are coming in from partner1.domain.com, use css1 - if they are from partner2.domain.com, use css2, etc.
This allows me to use relative paths throughout the code AND preserve the subdomain in the browser's URL bar.
One caveat - if you are testing in multiple environments (I have a DEV and a TST) you need some code to detect which environment you are in and operate a little differently, since the http header host would show something like "localhost:51510". For me, those subdomains only exist in my Production environment.
Credit to bgever - thanks!

Related

Redirect a domain name to a specific page in NGINX and Next JS

I explain you my situation,
I have a website that we'll called website-a.com that is link to my personal project.
On this project, every users can have a page, with the url my-project.com/[username]. So the urls will then be my-project.com/user1, my-project.com/user2, ...
For the context, I'm building it in Next JS, with the following code architecture :
--
pages
-- [username]
-- index.tsx
-- about.tsx
--
And I'm using Nginx with pm2 and a proxy pass that points to my http://localhost:3000
Now, I'd like to redirect a second domain name to a specific page of a user.
So I would like that when I go to user1.com, it displays my-project.com/user1 without modifying the url.
I pointed the DNS of user1.com to my server, I created a new host nginx and I made a proxy_pass to http://localhost:3000/user1. It's working, but I don't have the ressources css and js, because next is trying to load them from user1.com and they don't exists (user1.com/css/abc.css, ...).
I also tried to modify the build-manifest.json in the .next folder created after the build and it didn't work
So either I would like to find a way for Next JS to take the resources from my-project.com even if it is on user1.com (let it be an absolute path), or put a configuration with the nginx host but I don't don't know which one.
Thanks you for your help

Why browser URL cannot end with .com?

In my article site some users decided to have their eMail address instead of user name
The problem starts when i'm trying to redirect to a page using RouteData and the URL ends with ".com" , for example "example#gmail.com" is a valid username so his personal page will be
http://www.mysite/user/example#gmail.com
live example
As you can see the it gets redirect to home page and relative path gets messed up, so images doesn't show
Can someone tell me why browsers don't like routedata in their url ending with .com ?
If you try ".net" or ".org" it will work, that's the issue with ".com" ?
In Windows, the .com extension is used to denote a type of executable file. Your question is tagged as asp.net - so I assume you are using IIS. IIS does not manage virtual directory names containing executable extensions such as: .vbs, .com, .exe, etc.
When a virtual directory name ends with an executable extension (such as .com, .exe, .dll, or .sh), the files in this virtual directory cannot be viewed with a Web browser. For more info, see here.
One option you have is to simply replace . with an underscore _ for personal pages. So your example above would be: http://www.mysite/user/example#gmail_com

ASP.NET sub domain website's with same codes but different in Contents & Images

I currently have a website for eg:- www.domain.com & i need to create 3-4 sub domains for this website like
abc.domain.com,xyz.domain.com ...
I want to maintain the same codes for all the subdomains, & for each of the Sub domains i have the same look & feel except the css style, the logo's, the Page title's & few Page contents would be changing.
The titles & images(i will only store the image name) can come from the resource file,
Like for example i will have Resource file for each sub domains & my website should automatically pick the resource file based on the domain.
but not sure which is the best & easy way to achieve this.
Similar Question I have Seen based on UI Culture. I donot want to follow this approach. As i will be using English for all my subdomains & in future i will be having more sub domains.
If you have full-control over your web server and you are using IIS, you can achieve this easily by having multiple sites pointing to the same physical location in the file system. Then, each site can (and must) have a unique binding which will allow IIS to route incoming request to the appropriate site (sub-domain). Note that it is important that you have each site running on its own app pool rather than sharing the same app pool
Furthermore, you need to consider that the scalability of this approach is very limited, if in the future you need to have...say, hundreds of sites it can potentially add a lot of overhead to your web server. So, if you need a scalable solution you should go for a multi-tenant approach instead which you can easily load-balance.
One last note, images bundled up in resource files is a pretty bad idea...avoid it!!!
Site-specific content
Having different sites pointing to the same physical location doesn't mean that they have to share the same content all the time. You can still decide what content to serve dynamically based on the request context by simply inspecting the request object...this goes for dynamic ASP.NET pages, however for static pages you will need to create a virtual directory for each site and point them a location specific to that site only...this will allow you to customize the content for a specific site...see screenshot below how I have a "login" virtual directory which points to somewhere else...
Example
This is a very simplistic example. Suppose you have two sites set up...
en.domain.com
es.domain.com
The sites are pointing to the same physical location...C:\inetpub\domain\site
Then, there's a page index.aspx that has a panel in it that displays a welcome message...
<asp:Panel ID="pnlWelcome" runat="server"></asp:Panel>
for the "en" sub-domain you want to display "Welcome to Our Site" in english but for the "es" sub-domain you want to display "Bienvenidos a Nuestro Sitio" in spanish.
Then, if you set up a virtual directory for each site pointing to a separate location in the file system....say for the "en" domain the location is...C:\sitescontent\en\ and for the "es" domain the location is ...C:\sitescontent\es\, you can then place a user control, xml file, whatever you need inside these site-specific folders with the site-specific content. Then it is as easy as referencing the site-specific content with a virtual path...
string path = MapPath("~/content/{your_site_specific_content}");
or
Control ctrl = LoadControl("~/content/{your_site_specific_content}");
pnlWelcome.Controls.Clear();
pnlWelcome.Controls.Add(ctrl);
If you have a more complex architecture in your application, you would want to inspect the Request object to find out in which context the request is executing whether in the "en" site context or "es" site context....
HttpContext.Current.Request.Url.Host;
By NO means, I'm suggesting this the best way to handle localized resources in your system...it is just an example of how to handle site-specific content.

Wordpress development - local and remote paths

I'm trying to set up wordpress so that relative paths work on both my localhost development and my live site.
I was hoping it was just a matter of changing the "site" URL and "home" URL to http://localhost/ and www.example.com, and then links would be relative. However this is not the case, and I think .htaccess complicates the issue.
Eg, if I want to access a file in www.example.com/wp-content/mydirectory I can do this:
$url = '/wp-content/mydirectory/myfile.php'
but on my local site I have to do this:
$url= '/www.example.com/wp-content/mydirectory/myfile.php'
I have a solution by conditionally echoing a var at the start of the path, but it's not always possible to use PHP to accomplish this, for example, in a post or page where the link is in the content.
Does anyone have an elegant solution?
Go to the database and look inside the config table. There's a value for home (and possibly another value called URL, the table is not too big, so give it a quick scan), change that to your local environment for testing and when you're ready, you can change the record in the database and upload to your remote server.

What IIS 6.0 setting determines how a path is resolved?

I have a website that is deployed between 3 different environments - Dev, Stage, and Prod. For Stage and Prod, the site can resolve local paths to images with just the base url to the file, such as /SiteImages/banner.png. However, on the Dev server I have to hard code the full URL of the image path for the image to be resolved, such as http://server/folder/SiteImages/banner.png. Is there a setting I can flip to make the Dev server behave in the same manner as the other 2? I am using IIS 6.0 on a Win 2003 server.
There are usually three kinds of URIs that you can code in a website as far as I know.
Absolute: http://yoursite.com/somehing.jpg
This url includes the http:// and is
the full path to a resouce.
Root Relative:
/something/something.jpg
(In ASP.net
server-side only, you would use
'~/something/something.jpg')
This path is relative to the root of
your site.
File relative:
../something/something.jpg
This path
starts at the location of the file
that includes the URI. In this case,
it just back one directory (..) and
then goes back into the something
directory to look for something.jpg
What does the URL to the dev home page look like? Is it something like http://server/mydevsite/? If so, it sounds like you need to set up a virtual host.
Edit Just to clarify the above, say your prod and stage sites can be simply referenced as http://stagesite/ and http://prodsite/, if you use a path such as /images/myimage.jpg it assumes that the images folder are sitting in the root. In those two instances, no problem, images will display correctly. However, let's say your dev server is like the example I listed above. If your images are references as /images/myimage.jpg, instead of the server looking at http://server/mydevsite/images/myimage.jpg, it will instead look at http://server/images/myimage.jpg. If no images folder with the requested image exist in that server's root, you'll get an error.

Resources