Subclassing Global and overriding Application_Start - asp.net

I have a couple of web applications whose source code is missing. The project is compiled to a dll and is hosted on a IIS.
I have couple of questions to make.
What is the best way to recreate the
project from the dll file??
We are planning to change the
database server, and the database
connection strings are specified in
the Global.asax ( I mean the public
class Global : HttpApplication ). Is
there a way I can subclass this
Global and override the connection
strings? If yes, how can I make the
IIS refer to the new dll
Thank you all for any suggestions!!

For first part, use decompiler tools such as Reflector/ILSpy/dotPeek to convert IL code from DLL to higher level language such as C#. However, tools cannot get back comments, local variable names and project structure. You need to manually organize the code into files and project structures. From aspx files, you have to figure out the code-behind classes and then link up the source of the class into a correct named code-behind file - for example, if default.aspx says that it inherits from MyApp.Default then create file default.aspx.xs and put the source code for the class into that.
For second part, you can create a new class derived from Global and modify Global.asax to use that class - you need to put the assembly containing new class in bin folder and overwrite inherits clause in asax file to point to the type name of new class. You anyway need to inspect the code of your current Global class (using tools sighted above) to see if you can override connection strings by sub-classing.

Probably the best tool available to reverse engineer a dll into code is .NET Reflector. Unfortunately, the latest version is no longer free, but it is worth the money.
I am not sure exactly if this still applies if you can already reverse engineer your source code. However, I would recommend moving your connection strings outside of your project into web.config as a best practice. This way you can make the change in the future without changing any code.

Related

References and external class use problems

Using Visual Studio 2015 on an ASP.NET project. Everything works fine except now I have a block of code (A common AD utility function) that I want all the pages to be able to access. The original language (inherited project) is VB.NET, but it should work just fine either way.
I created a class file, named it CommonADFunctions.vb. The file uses System.DirectoryServices, and there's a reference in the project to that assembly. However, there are two problems:
I can't reference the new class to call the functions from any of the page code files. This includes attempts to instantiate a new variable as the class type.
When I move the new .VB file into App_Code, the reference to System.DirectoryServices breaks, and it refuses to build.
This may seem like a trivial ask, but what am I missing?
Turns out this was a simple property on the file itself I created a new Class File, and somehow the Build Action got set to Content rather than Compile. Setting this to Compile allowed the object to be referenced and instantiated properly. It doesn't fix the IDE intelliSense from APP_Code for DirectoryServices references in the code, but it compiles and runs, which is what I needed.
EDIT: Received external help which pointed this out.
Without code and screenshots to illustrate I can only recommend a few things to try.
I can't reference the new class to call the functions from any of the page code files. This includes attempts to instantiate a new variable as the class type.
The methods in the class have Private or Friend scope.
Its a static class (a Module in VB.Net) and you do not need to instantiate it.
You are somehow referencing an old DLL which doesn't have the methods. Check the reference to this AD project and make sure its "Referenced" via Project.
When I move the new .VB file into App_Code, the reference to System.DirectoryServices breaks, and it refuses to build.
This sounds like a corrupt project file. Clean the solution, delete the .suo file, delete the obj & bin folders.
Then move the CommonADFunctions.vb to the App_Code folder and add the DLL reference to System.DirectoryServices. Or create the CommonADFunctions.vb file in App_Code to start with.

Copying/Moving App Code to New Project

Ok, I am in the process of breaking apart of intranet application (VS 2010 Web Site, ASP.NET Web Forms with VB code behind). During this process i'm trying to convert some of our our app_code files in to WCF rest service in a new project. However, when I copy or "add existing" vb files into the new "services" project. I get tons of errors including...
error BC30002: Type 'XXX' is not defined
warning BC40056: Namespace
or type specified in the Imports 'System.ServiceModel' doesn't
contain any public member or cannot be found. Make sure the
namespace or the type is defined and contains at least one public
member. Make sure the imported element name doesn't use any aliases.
From what i've read it may (or may not) have something to do with Assemblies and references that I just have very little knowledge on. I have added the namespaces from the current web.config to new project's web.config, and the files are identical. So there is something in the background that needs to be added to the new project I just don't know what its.
PLEASE HELP!!
THANKS
JOSH
UPDATE 1
So one of the errors i'm getting = "error BC30002: Type 'MailMessage' is not defined." Which is a namespace that is added to the web.config, which apparently isn't being picked up??? IDEAS?
I've come across a similar issue - not sure what the reasoning behind it is, but I got around it by creating a new .vb class with the same name as the one you want to copy, then copy and paste all the text from the old one to the new one. Save it, then it seems to like it - it didn't like me copying and pasting the actual file, nor did it like me adding existing files.
Hope this helps :/
This issue seems to be tied to the the differences between Web Application Projects versus Web Site Projects. Eventually I had to add different namespaces on the new project level.
Here is more info about WAP vs WSP....
http://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx

converted web site to web application, works without namespaces

I converted a web site project to a web application using this guide
http://msdn.microsoft.com/en-us/library/aa983476%28v=vs.100%29.aspx
In the guide it says that I have to add namespaces to my classes but I did not do that. The classes I have in the Old_App_Code directory are not placed into namespaces and the application runs just fine (tested on different machines). Is it because there is something special about Old_App_Code or am I missing something? Thanks.
You are misinterpreting what the guide is saying, it is NOT saying that you need to add namespaces to get the code to compile, but rather that the conversion process does not add the namespaces into the code files by using the folder/file naming constructs.
The guide is further underscoring the fact that when you add new items (i.e. classes) in a web application versus a web site; the namespace is automatically added to the code file, based upon the folder structure and file name of the of new class.

Do app code support only to put one kind of file?

Do app code support only to put one kind of file, i mean either c# class or vb class?
Because if i put both sort of file and create an object then, application throws error.
How can i make App code compatible with both.
Within a single assembly or project you can only have one kind of source code, although you may reference multiple assemblies (of different languages) within the same project.

Visual studio refactoring - move class to assembly

I'm looking for the simplest (and most complete) mechanism to move a class from one to another assembly with reference (dependency) fixing capability.I know some manual ways to do that like :
- use built-in move rename, then cutpaste, multiple save ...
- use resharper rename namespace, cutpaste , the same as above
but with the problem is the same with those : in a web environment (namely ASP.Net) almost all of the references (for user controls for example, let's suppose with assembly name in their path for a virtual path provider scenario) are coded a string references (not to mention the configuration files and other external reference sources) - unfortunately even resharper doesn't found all. Other problem is with the designer files - you know they're generated on at least save action accordingly to the specifications in control and sometimes they're somehow mixed with the rename action I mean here's the old there's the new assembly name etc.
Thanks in advance,
Nicolai
If you are using Resharper try the Test Driven Development
It Allows a number of refactors like that.

Resources