-1


so this is driving me crazy...
I'm working on a website in Visual Studio 2015 (so from the start page: File>New>Web Site... NOT New Project>Web>ASP.NET Web Application) and things are going well when I use VS as the debugger/localshost.
Now, being cautious, I want to upload the site to a www.mysite.com/sandbox/ folder where I can test out some further items such as database access and the like (since the site is live, I don't want to replace it until I'm ready). But for some reason, all files (which worked fine through localhost) seem to point to "/" for the master pages and other items rather than "/sandbox/" ...
Is there any way that I can tell VS that the root is not where it thinks it is? So far I've verified that this is purely something with the root location: I've cautiously created a different project (with file names that I can easily find & delete on the live server) to see if anything is wrong on the server, but they load fine if I keep the root in the files the same as the root on the server (in other words, if I uploaded my site to the root, the references would be ok). BTW, I've done this in the past where I directly worked at the root level for a site that wasn't active and all worked well.
Is there any way that (perhaps in web.config) I can tell it that any time I set MasterPageFile= "~/Master/masterPage.master" on a page it should actually point to MasterPageFile= "~/sandbox/Master/masterPage.master" ? I was under the impression that the "~" would take care of that, but apparently not? Based on Google searches, I have found that in Web Applications (rather than Web Sites) there is a way to define the 'Web' part, but that option does not seem to be available here...

Any help would be greatly appreciated.
Thanks,
JoeE

EDIT:

So, I'm told this looks like a "wall of text" (whatever that may mean)... Let me give more details with a step by step for an example, perhaps someone can slap me in the right direction.

  1. Open VS2015, go to File>New>Web Site... Pick from
    Installed\Tempates\Visual Basic\ASP.NET Empty Web Site -> OK
  2. Right-Click on the Item under the Solution and Add>Master Page, then edit the MasterPage.master to have this content:

        <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
    
        <!DOCTYPE html>
    
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title></title>
            <asp:ContentPlaceHolder id="head" runat="server">
            </asp:ContentPlaceHolder>
        </head>
        <body>
            <form id="form1" runat="server">
            <div>
                <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
                Some Content from Master
                </asp:ContentPlaceHolder>
            </div>
            </form>
        </body>
        </html>
  3. Add>Web Form (Default) and edit its contents to read:

<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/MasterPage.master" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" >
    <p>Some Data from Page</p>
</asp:Content>

Now I Test Run it at this point with F5 and I get a browser window that says "Some Data from Page"... as expected.

Now comes the time to upload it to my server (hosted by 1&1):

When I click Publish, it takes me to the Default.aspx page but states:

Parser Error 
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

 Parser Error Message: The file '/MasterPage.master' does not exist.

Source Error: 



Line 1:  <%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/MasterPage.master" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Line 2:  
Line 3:  <asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" >

Source File: /sandbox/siteTest/Default.aspx Line: 1

My question is this: where do I need to tell Visual Studio that the folder structure really contains everything under the "/sandbox/" folder rather than just "/"? I understand that I can go into the Default.aspx file and change the statement to MasterPageFile="~/sandbox/MasterPage.master" but there -has to be- a better way...?? I was expecting that the entry in the Publish option would do this, but it doesn't... alternatively, I tried to programmatically change this during the PreInit event, but that didn't work...

Thanks,J

JoeEg
  • 1
  • 3

2 Answers2

0

First, ensure that you actually are using ~/ in all of your app-root-relative URLs.

Second, ensure your application is inside an IIS Application Scope - this is the most important step, because it's how IIS tells ASP.NET that /sandbox/ (a subdirectory) is the root of your application instead of / (the root of your website).

In IIS Manager, open your website in the tree-view on the left and select the directory (or virtual-directory) that represents the root of your application, right-click it and choose "Convert to Application".

Also ensure that your application's root web.config and bin directory are in the /sandbox/ directory and not the root of the website itself.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • When I publish the site, it get a "Parser Error Message: The file '/Master/masterPage.master' does not exist." I've checked and the master page is where it should be. – JoeEg May 12 '17 at 00:52
  • Regarding the IIS Manager... I don't have access to that. Also, I don't want to 'convert it to an Application', that's not the issue AFAIK... web.config is in the /sandbox/ folder. There is no /bin for a Web Site (there would be one for a Web App)... – JoeEg May 12 '17 at 00:54
  • @JoeEg "Convert to Application" has nothing to with "ASP.NET Web Application" projects. An "IIS Application" is how IIS segregates different areas of a website and sets-up the `~` system in ASP.NET. – Dai May 12 '17 at 01:06
  • I don't want to mess with the root itself and risk affecting the existing site, nor do I have access to IIS Manager through my hosting company. I was expecting some way to set this in VS... – JoeEg May 12 '17 at 01:37
  • @JoeEg Most IIS-based web-hosts do allow access to IIS Manager by using the Web Management Service. Alternatively you could just ask them to create the Application entry for you. If not, you will need to modify your ASP.NET Website to be built on the assumption it's running from the `sandbox` subdirectory, but you won't be able to run it anywhere else. – Dai May 12 '17 at 02:07
  • I cannot find any form of access through my hosting company and asking them to do anything is not really an option. How do recommend that I 'modify your ASP.NET Website' to do this? Are we talking about changing each MasterPageFile= statement to have an absolute path? – JoeEg May 12 '17 at 03:10
  • @JoeEg Yes. You'll need to move all of your files in your website project to a "sandbox" folder and change all of your links and references to have a "sandbox" prefix. – Dai May 12 '17 at 03:39
0

Alright... I think I found a solution. Perhaps just a touch bit hack-y, but it works for what I need and hopefully someone else might find this useful. After trying some other options, the one that works for what I need is to keep the structure as-is but to use a subdomain for the testing. So now I publish to sandbox.example.com rather than example.com/sandbox The server now considers the "~/" folder to actually be where I point the subdomain to.

Thanks for the effort & feedback.

JoeEg
  • 1
  • 3