ASMX dll not loaded when in subfolder - c#

I am using ASP.NET (3.5) webforms. I have a plugin for a website that contains an .ascx file and an .asmx file. My folder structure looks like this:
MainWebSiteFolder
bin
Plugins
Plugin1
Plugin1.ascx
Plugin1.asmx
bin
Plugin1.dll
At runtime, the main website (using the web.config tag) can find the Plugin1.dll and load the Plugin1.ascx into the webpage. The Plugin1.ascx contains javascript code that calls the Plugin1.asmx, but IIS can't find the Plugin1.asmx codebehind because it's looking for Plugin1.dll in the main website's bin folder instead of the plugin's bin folder.
Trying to reach the asmx directly via URL (http://MyWebSite/Plugins/Plugin1/Plugin1.asmx) results in the following error:
RunTime Error
Could not create type 'MyNamespace.Plugin1'.
Line 1: <%# WebService Language="C#" CodeBehind="Plugin1.asmx.cs" Class="MyNamespace.Plugin1" %>
There are several similar questions out there, but none of them solve my problem because I just own the plugin, so I don't want to copy the plugin.dll into the main website's bin folder (because, when the main website is upgraded, its bin folder is emptied. I don't have control over this). I also don't want to make the asmx its own separate IIS application because it needs to be able to share a session with the main website.
Is there anything I can do to connect the asmx file with its dll inside the subfolder?

Check if adding a web.config to the Plugins or your Plugin1 directory (web.config inheritance), containing an assembly probing-element works (see probing Element on MSDN).

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.

Why can't I see the Controllers folder within my deployed MVC web app directory?

I have recently purchased a shared web hosting package, provided by GoDaddy, and deployed my own MVC web application to it.
My problem is that, when on the control panel (Plesk) provided by the host, I can't find the Controllers folder that contains all the behind code.
Is there a reason for this folder being hidden?
I'm guessing it's because the files within this folder are being used by the server all the time and can't be accessed/changed incase it f--ks everything up... But I am not sure about it because I am quite new to web hosting.
Thanks for any assistance in advance.
All your cs files including controllers will be compiled into DLL files. Please open "bin" directory to find all your DLLs.
When you deploy, u ll not get controller, because it contains c# code which changed to dll available inside bin folder.
Not Only Controller, the other folders which are having C# code like "App_Start"...and etc...will be changed to dll and will be available inside bin folder.
In the case of Model/s, if you are using Entity framework, then, the .edmx file will be available inside the Model folder.
All your Business logics including controllers, models and core etc are converted to dll and by Assembly name dll is created in bin (released or debug folder)

Can you have multiple APP_CODE folders in a project

I inherited this code from another developer (3rd party) but I am implementing it. Its a large website done in c#. For twitter integration they must have created a new website project because the code inside the sub folder has its own bin and app code folder. This is published on IIS but its a strange setup where it compiles at run time. (If I make a code change to a file on the webserver and save it, it updates instantly without having to publish).
This subdirectory is throwing a 500 error and I assume its because I dont believe you can have multiple bin and app_code in the same website project. Is that a correct assumption. Should I combinbe all the app_code directories to the one in the root? Here is a more visual example of the directory layout:
MyWebsite
App_Code
BIN
...other folders and files
MySubdirectory
App_Code (ALLOWED??)
BIN (ALLOWED??)
App_Code and Bin are special folders only at the root of the application. You should make MySubdirectory a child application in IIS.

ASP.NET Build - Bin Folder vs CodeBehind File

Assume there is a asp.net 4.0 web application and it has a default.aspx and default.aspx.cs files in it. After I build the project, a dll that is named of the project created in the bin folder. So what the dll contains ? All code behind files compiled versions ?
If the aspx files still refers its CodeBehind file like below, then does the dll used for this aspx file or still code behind is valid to run the project ?
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication3._Default" %>
In a Web Application, all your C# code is contained within the DLLs in the bin directory. There are a couple of exceptions, such as DLLs that you rely on that live in the GAC, for example. Using a web application ( your question says this is what you are using ), you do not need to deploy your *.cs code behind files.
A Web Site is different. Changes are detected and recompiled on the fly. You'll need to include your C# files code-behind files when creating a Web Site type project.
ASP.NET Web Site or ASP.NET Web Application?
A DLL is a library that contains code and data that can be used by more than one program at the same time:
What is a DLL?
Code-behind refers to code for your ASP.NET page that is contained within a separate class file. This allows a clean separation of your HTML from your presentation logic:
ASP.NET Code-Behind Model Overview
The code gets compiled into the assembly produced by your web project. You can change its name and default namespace as part of project options.
As I understood it, the ASPX file is only used IF the project is marked as being updatable, otherwise it is just a placeholder file.

Does an assembly maintain its directory structure?

Since all files in a web project are compiled into single assembly, then does this assembly maintain a directory structure? For example, if a file in a root directory references a file in a subdirectory, then how could this reference still be valid when the two files get compiled into same assembly?
Assume a web project has the directory structure shown below.
Since all of web project’s ASPX files get compiled into a single assembly WebProject1.dll, how is this assembly able to record/memorize the directory structure?
Thus, when you deploy WebProject1.dll to a web server and user makes a request for http://WebProject1/some_SubDir/default.aspx, how will WebProject1.dll be able to figure out which Page to render?
WebProject1\SubDir (where WebProject1 is a root directory)
WebProject1 -- contains several ASPX files
WebProject1\SubDir -- contains a file default1.aspx.
When we deploy the Web project, must we create the same directory structure on a web server (WebProject1\SubDir), even though we won’t put any ASPX files into those directories?
I assume that on Web server WebProject1.dll should be placed into the Bin directory?
thanx
EDIT:
Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server.
My book says that when using Web project all web code is compiled into single assembly. I thought “all code” includes aspx files?!
Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure
So if I add a new aspx page via Project --> Add New Item, and store this aspx page in a subdirectory named Hey, then this page will reside in namespace WebProject1.Hey?!
But how do I do add new item into a subdirectory, since Project --> Add New Item doesn’t give me an option to browse and choose a directory I wish to save it in, but instead automatically creates aspx file in a root directory?
The relative path is kept when the compiler generate the dll.
I’m not sure I know what relative path you’re referring to?
thanx
Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server. For example you project in Visual Studio may look like the following:
WebProject1 (The root project)
|
|- some_SubDir (A physical directory inside the project)
|
|-default1.aspx
|-default1.aspx.cs (assuming a C# project)
Once you have compiled the web app you'll need to upload the following to the server:
WebProject1 (The root directory for your website)
|
|-bin (The binary directory created by the build)
|
|-WebProject1.dll (The compiled source code of the web app)
|-some_SubDir
|
|-default1.aspx (The file that will map to the URL www.websitename.com/some_subdir/default1.aspx)
Compiled resources (non-sourcecode files that are compiled and stored inside the assembly) are different issue that are addressed in your other question
Edited to add direct answers to the questions:
Not all files are compiled into the assembly, only source code files are. Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure, but it doesn't have to be.
Your default1.aspx file will have in the header something like:
The inherits line tells the webserver that when a user requests this page it should be processed in conjunction with the source code that defines that class, which it will find inside the compiled assembly. The combination of the physical aspx file and the compiled class will generate standard html which is then passed back to the client.
Yes, you need to create the same directory structure, but you are required to put the aspx files in there.
Yes
(can someone please edit this if they know how to get the list items to number correctly, please?)
All those path information will be embedded as Meta Data/resource file, so, you can deploy it safely to the server. The relative path is kept when the compiler generate the dll.
I suggest you use Reflector to open the dll, and you can get a much more deeper understanding what is inside dll.
Notice how some_Subdir/default1.apsx has a 'Inherits' key/value pair in the page declaration?
What this means is that when you make a request for that resource IIS goes 'Ah ha! Asp.Net needs to handle this request! Hey asp.net please return me some html to send down'
Asp.net parses that aspx file and creates a proxy class on the fly that inherits from WebProject1.some_Subdir._Default1. This proxy class then parses out the control tree and html, and kicks off the page life cycle (this is overly simplified, and I'm sure I've missed some details).
So the WebProject1.dll is just the actual C# / VB of your web app, but in concert with the asp.net worker process and the markup you can render html back to a client.

Categories