How to map a virtual directory to a website in VS? - c#

I am developing a C# VS 2008 website, trying to add a Master file. I created a virtual directory in IIS housing the "Master" folder, containing the Master files.
Now how do I reference these files from my website in VS? One problem is I do not know where I need to publish this Master folder to. Other problem is I do not know how to reference this Master file in my aspx Page directive.
FYI, this master folder is physically located outside of c:\inetpub\ in a totally separate file location. Is this a problem?

I don't think you'll get away with using a virtual folder for that because any pages that refer to the master page will be in the same application space as the master page (remember that master pages are just user controls). You create child pages by using Visual Studio or Expression Web to select "create from master page"

Related

Why am Igetting the error "Could not load type 'CADE.main.index'." on a new server when I'm using the same code on all other instances, how fix it?

I just checked out my "mixed" (asp classic and .Net) web site source from SVN on a new Windows 2019 Server. When I go to the logon page (.asp classic), it's fine but when you logon and call the main page (.aspx) it throws the error: "Could not load type 'CADE.main.index'" and displays:
Line 1: <%# Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CADE.main.index" %>
This SVN code is running on 15+ servers, including one 2019 Server. The code behind looks like:
namespace CADE.main
{
public partial class index : BasePage // Override with BasePage
{
IIS and everything under Application Development is installed. IIS serves .asp, .txt, .gif, .png, even .Net handlers (.ashx) and web services (.asmx), just not the aspx pages.
So, I rebuilt the solution with VS2019 and published it, gave administrator permissions on the app pool, gave "Everyone" full permissions on the entire web, deleted the bin directories in both the source and web locations, ensured output path was bin/, cleaned the project, don't think I should change CodeBehind to CodeFile, and tried about every other thing that people have suggested on this web site but nothing has eliminated the error.
Question: How do I fix this error so the .aspx pages loads?
EDIT #1: 15 hours after post
I'm not sure but with this information maybe this should be a new post.
This error ONLY happens on the second web site. IIS is serving two web sites, separating them by host name (web1.com vs. web2.com) in bindings. They both point at the same file structure. Web1's subdirectories are natural while Web2's subdirectories are virtual directories that point to Web1's.
Web1: Normal IIS web
wwwroot
LMW (subweb, LMW/Main/index.aspx is page in question, but works here)
Web2: Second web in IIS, based on host name, uses Web1's folders as virtual directories.
wwwroot
WEB2 (folder under wwwroot)
LMW (virtual directory points to Web1/wwwroot/LMW. LMW/Main/index.aspx gives the error here)
Question: Why doesn't the .aspx work when it's a virtual directory?... it's the same file as is in Web 1?
EDIT #2
It is working but I don't know what I did to fix it. I'm sure I changed something but I don't know what it was. So, I created another web like web #2, New web folder under wwwroot with LMW a virtual directory pointing to Web1/wwwroot/LMW! I'm seriously missing something, Any ideas?
These errors occur if the .aspx page or the Global.asax page contains a reference to a code-behind module and if the application has not been built.
You could try the below method to build the application:
Use the C# command-line compiler (CSC.exe) to run the following command:
csc /t:library /r:System.web.dll /out:mydll.dll myfile.cs
OR
In Microsoft Visual Studio .NET, click Build on the Build menu.
Also try changing CodeBehind="index.aspx.cs" to CodeFile="index.aspx.cs". This change is required when you change project type from website to webapplication or vice versa.
make sure you install the .ne framework feature of iis.
I actually created a brand new web that used a Virtual Directory for it's codebase that is the same code as the other webs.
Index.aspx resides in the /lmw/main directory. I had created an Application on that folder when I was creating the other applications in the web. So, I removed the "Application" from /lmw/main and it worked.

No cs file if MasterPage used

I am currently using Visual Studio 2012 to design aspx pages and have a page which uses a MasterPage which I will call it "a.aspx" for simplicity's sake, and unlike my other pages, "a.aspx" does not have a .cs file attached to it which I assume is because it had a Master Page. Whenever I drag items like buttons into the contentholder of "a.aspx", the code behind page brings me to the aspx page and not the cs page. And I can't import assembly references which I need to because I require some SQL connection in "a.aspx"
So how can I create a webform with a master page while being able to have the contents within my contenthandler to be mqanipulated through a .cs file or can I perform functions in the aspx page too?
You can have all your functions in same aspx file, or you can divide it into two files: aspx and cs. Just enable "place code in separate file" checkbox in "add new item" dialog.
This place code in separate file option depends on the type of project you are building:
1) If you are building a Web Application then (File | New > Project, doesn't have an /App_Code folder, compiles all .cs/.vb files into one .dll in the /bin folder) then you don't have the option to not create a separate code file, and when you add a new item it's either a Web Form or a Web Form using Master Page.
2) If you are building a Web Site (File | New > Web Site, contains an /App_Code folder, the code is not compiled into a .dll in the /bin folder) then you will have the option (ticked by default in VS2008/2010/2012) to Place code in separate file, and also Select master page.

Debug current page in ASP.NET MVC

I have a MVC4 project in VS2012.
How can i debug the current open page in VS in the browser? When i select "current page" in project properties always the path with the Views folder is opened. The path should be without the Views folder.
When i select "specific page" and leave the textbox blank always the root directory is opened.
If you are using the MVC framework you are most likely using the routing system.
To specify your starting page you need to give your project the path you want to open and not the view name (and selecting "current page" doesn't work because Visual Studio has no idea what route can be used to display the view your are on).
You need to manually set the Specific Page in your project option (under the Web tab) to the path you want to use (let's say you want to call your home path, then just fill up the field with home).

ASP.NET Master Page Parse Error

I have a Visual Studio 2010 project with a Master Page that works fine.
~/Site.Master
In the same project is a Folder with another directory structure that needs to use another Master Page.
/xr
Within this folder, I have included the Master Page for those files.
/xr/XR.Master
My Default.aspx file attempts to access this Master Page using the following include:
<%# Page Title="XR Project" Language="C#" MasterPageFile="~/xr/XR.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test1.Default" %>
Debugging on my machine in localhost works fine, but whenever I deploy it and try to navigate to the Default page in the xr folder, I get
Parser Error Message: The file '/xr/xr/XR.Master' does not exist.
However, the Source Error returns Line 1 as I have shown above.
Here is what I tried:
I moved the XR.Master page into the root folder and changed all of the files in the xr folder to reference the XR Master Page using the following include:
I debugged and tested the code on my machine using localhost, and it worked fine.
I pushed it out to the remote website and got the new error:
Parser Error Message: The file '/xr/~/XR.Master' does not exist.
What am I doing wrong?
EDIT: I do not like posting a link to the page, but I will for a short time until this is resolved:
Projects
From there, you will see everything works well enough except for the link to XR1200.
Here's the best advice I can give ya without knowing too much about your project structure.
I'm hoping you are using VS2010 so that things will look the same for you as on my machine.
One easy way to get the path of your master page all figured out is to add a test web page from masterfile, the path will be preset for you and you can use that in your existing pages.
Here is my blogs project structure.
Right click the folder where you want to add the test page and click add new file.
Add a new web form using Master Page. This is just for testing.
Now locate your Masterpage and select it.
From here just find your newly added content page in your solution structure and check the code files for the path to your masterpage.
Once you've verified that your path is correct, if it still bombs once you publish it then you've got either an issue where not all of your projects are building properly, or you're files aren't being uploaded properly and that is going to end up being something that you may just have to find on your own. I still suggest blowing away anything in your pub folder on your server and trying a clean publish.
Hope this helps!
my guess is that the iis setup is different on the different machines. typically, you see something like this when you have one machine set up with the site itself as a website and another machine set up with the site itself as an application within a website (like the Default Website). it looks like you have addressed this possibility by using the ~ in the path, but perhaps the iis on which you are deploying does not have the site directory itself set up as either a website or an application, but is merely a subdirectory of a site. in that case, the ~ would refer to the website directory (perhaps named xr?) and the site is in a subdirectory of that named xr. if this is the case, the solution is probably to set up iis such that you have the application directory configured as an application on the server to which you are deploying.

How to specify physical path in ASPX page?

I am developing a C# VS 2008 / SQL Server 2008 ASP.NET Web Applications project. In one of my ASPX files I am trying to reference the Master file, which is actually located in the parent website. In other words, when I open the parent website, I see this project listed. But when I open this project separately, I do not see parent website and this project is the root.
So now how do I use the Master file from the parent website? Currently, I have in my ASPX file:
<%# Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="EnhancedCreateUserWizard.aspx.cs"
Inherits="Membership_EnhancedCreateUserWizard" Title="Untitled Page" %>
But this won't work because it is a virtual path and since this project is the root, I can't access the Master file virtually. Instead I want to specify physical path. How accomplish I do this?
You cannot share a master page between applications this way. All paths within an asp.net app are relative.
The virtual path provider simply will not reach above the current apps root.
You will need to either write a custom virtual path provider, which is not trivial, or package the master pages in a shared assembly.
You will find guidance in this question: What is the best way to share MasterPages across projects

Categories