adding .net code to a classic asp website, can't reference namespaces in .dll file - asp.net

I have an existing fairly large classic asp website, with virtual directories configured to centralize certain resources. My problem is for some reason I can't access any of my namespaces and classes. I tried adding a reference to another project where I have classes in a namespace "DAL" and even though intellisense sees the classes and the website compiles fine, it errors when I try to access any page that references a class in the "DAL" namespace.
I get the following error message in my browser "CS0103: The name 'CMS' does not exist in the current context". Part of the problem is website project's root is not the same folder/level as the web root in IIS. So my libraries are in the website root "/bin" folder, but iis is looking for these files in the IIS webroot which is at a lower level. So how can I get .net to see my binaries without putting them in the lower IIS website root directory? I tried setting up a virtual directory to my .dll file but it seems to have no effect.
thank you for your help!
======================CLARIFICATION====================
What I'm trying to do is keep the .dll files I want my website to use in a higher level directory then the folder I have set as the web root in IIS. So say the library i want to use it "DAL" it in the projects /bin folder, but under IIS the default site's Local Path is set to "/site/default". The only way I can seem to use the "DAL" library is by putting the /bin folder into "/site/default/bin", which for this project is not an option. Does this help?

Using an NTFS Junction Point to achieve what sounds like the same goal has been working for me.
By way of an example, I have a web site with 20+ child IIS Applications that are largely identical (don't ask!), rather than duplicating the 'bin' folder in each of these (they would be identical) each child application has a 'bin' junction that points to the 'bin' folder in the web site root.
/bin <- this is the actual 'bin' folder
/app1
/app1/bin <- this is a junction point
/app2
/app2/bin <- this is a junction point
/app3
/app3/bin <- this is a junction point
/images
...
...
To create these junction points, if you're using Vista/Win2k8 or later you can use the built-in command 'mklink', for earlier versions of Windows use the SysInternals junction.exe tool - available here.

Maybe make the website route folder a nested application in IIS?

Related

ASP domain and files

I have no idea about asp, but I had to do some modifications in a web site, an easy modification. So I downloaded all files from server and I did all the modifications in Visual Studio 2013. Then I tested each page in the local host and it was perfect.
When I uploaded the files, I created a folder called "development", to tested it before I changed in the real site, so, my real site is for example "www.realsite.com" and my new folder is inside, with all the file, so I write in my url "www.realsite.com/development" and it shows the page, but not the one I had modified, but the real site. I want to know if there is a config file to change the path of the development site to see the changes I make and not the real site, because if I click in the development site a menu, it sends me to the page in the real site.
I hope you can help me with this,
Thank you!
PS: Do you know what is the meaning of "~/" in for example : src="~/folder/folder/xxxx.xx"
This is because the URLs in the project are using absolute paths, all pointing to the root. If they were using relative paths, moving the project to a folder and running it from there would work just file.
The difference:
... <-- absolute, note the leading slash
... <-- relative, no leading slash
Well, it depends on what kind of changes you are referring to, what kind of ASP.net site (or application).
The ~/ in ASP.Net means "path from application root". A subfolder (the new folder you created) in an existing application is just that, a folder. It is not "another application root". So if the existing code refers to "its root", e.g. where it uses ~/, it's probably not what you would expect..
Again, not enough info, but if you experience more unexpected behavior, it will probably be because of this (application scope).
Ref: ASP.NET Web Project Paths
ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application.
Hth...

Setting up application and resource folders in sub virtual application

I am looking to use the below asp.net 4.0 web application structure but not quite sure how to achieve my result as explained below. What configuration will be needed to handle path issues for referencing both. For example ~/css/style.css needs to dig into the WEBSITE. I know I will have to create a helper for RESOURCES -- WebResourcePath("images/image1.jpg") returns full path if that works in a separate virtual directory?
Default Web Site
>SAR-GROUPS
SARGROUPS_WEBSITE
SARGROUPS_RESOURCES
All website files like aspx, js, css, etc. normal web files go in the WEBSITE folder. The RESOURCES folder will contain other files like pdfs, xml, txt, images, and files . These files will not need to be uploaded or updated during deployments and can remain untouched. When I deploy the WEBSITE I only need to delete the WEBSITE folder and copy the new precompiled folder in SAR-GROUPS again. I have to deploy like this as it is automated deployment from scrips that run so this is an xcopy deployment.
Does anyone have good practices or a working setup to achieve this. I am not looking at alternate methods unless it cannot be done or the other way is much better for auto builds.
Thanks
If the files in the SARGROUPS_WEBSITE directory need to reference resources in the SARGROUPS_RESOURCES directory then why not just make the SARGROUPS_RESOURCES virtual directory inside the SARGROUPS_WEBSITE directory? This way you can point the SARGROUPS_RESOURCES virtual directory at a physical location on the disk and delete the contents of SARGROUPS_WEBSITE without touching the resources.
So structure would be
Default Web Site
>SAR-GROUPS
SARGROUPS_WEBSITE
SARGROUPS_RESOURCES
But the physical structure could be anything
You can then reference them like
~/SARGROUPS_RESOURCES/css/style.css
*untested
EDIT
You've totally not understood my answer and/or virtual folders.
Physical structure example:
D:\Inetpub\WEBSITE
D:\Inetpub\RESOURCES
IIS structure:
IIS Root -> Site (that is a website and points to D:\Inetpub\WEBSITE)
IIS Root -> Site > Resources (that is a virtual directory and points to D:\Inetpub\RESOURCES)

How might i setup my ASP.NET project to find my files?

edit I do not want to redirect pages, specific files etc. I would like to change the path where images, videos and other media are stored from the root source directory to the directory of my choosing. In this case c:/dev/prjfiles/prjname/public (c:/dev/prjfiles/prjname/ is my working directory) and i except when my html does img src="/pic.png" it will find the image in c:/dev/prjfiles/prjname/publi/pic.png. I need a working solution, i tried looking at how to set virtual directories and etc. I cant figure it out. Thus the bounty. I am generating the html, i am not writing asp:image runat="server" etc i am pulling data from a DB and outputing the html. The part that is still a WIP is the code that handles POST request. The html already exist but i cant have hundreds of files in site.com/here pollution my source directory (c:/dev/trunk/thisprj/thisprj/where my .aspx files are and i do not wish 500 .png/gif/jpg here)
I dont know how asp.net environments are usually set up. I am assuming i have a root path that is not available from the web, a bin/ where i may put my asp.net dll and a public where i stick in any files i want.
I would like to have my project files seperated from everything else. My JS, css and image files are in prjfiles/prjname/public with my sqlite db in prjfiles/prjname/ and extra binaries in prjfiles/prjname/bin.
The problem comes when i run my app and try to load an image. Such as /cssimg/error.png. My project does not find resource in my /public folder and i have no idea how to make it find them. How can i set my project up so it does?
NOTE: I set the working directory path so its at prjfiles/prjname/. In code i write ./bin/extrabin.exe and db.sqlite3 which access the files properly.
You might want to watch the getting started videos for ASP.NET
http://www.asp.net/get-started/
EDIT: More info added
As #Murph suggests, your assumptions are incorrect.
IIS takes care of blocking HTTP access to any important files and folders like your *.aspx.cs, and *.cs in the App_Code, any DLLs, anything under the App_Data directory and the web.config.
Content files, such as *.html, *.css, *.js, .gif, .jpg, .png are all served in the normal manner.
In this way, there is no need for a "public" folder.
I dont know how asp.net environments are usually set up. I am assuming i have a root path that is not available from the web, a bin/ where i may put my asp.net dll and a public where i stick in any files i want.
This is wrong assumption!
You have a root folder, which IS available in public. You set IIS or ASP.NEt Development Server to this folder.
(optional, but always needed) You have a web.config file in this root folder for configuration
You have a bin folder for your assemblies (each page or user control "include" compiles to a class)
(optional) You have App_Data as default folder for file-based DBs and/or other data files (say XML storage, ..)
(optional) You have an App_theme folder for styling and images. Read about ASP.NET themes.
(optional) You can add App_Code folder if you want to add classes to be compiled by the server.
You can create folders for scripts, etc...
Normally for complex logic, etc.. you create in a separate project outside the root and reference the result assembly in the bin folder.
Seriously, you cannot do ASP.NET work without an IDE or a manual. Visual Web Developer 2008 Express IDE is free and http://asp.net has tons of resources for getting started.
I don't know if I got the question right, but maybe you could try the <BASE> HTML tag.
HTML <base> Tag
"Specify a default URL and a default target for all links on a page"
There's a nice and simple example at W3Schools, check it out.
The negative side is that you need to put a <BASE> tag in each page you want.
It sounds like you should be able to create a virtual directory to do what you're asking -- but it's a very non-standard setup.
Keep in mind that IIS will prevent users from downloading DLLs and other project-level files, so you usually don't need to partition them off in a separate layer.
For example, just have a cssimg folder at the top level of your project, and skip the whole public folder thing.
I see where you're coming from. ASP.NET projects are set up a little differently from how you're treating them, but you can make them work like you want.
The root of an ASP.NET project IS publicly accessible. When you created your WebSite within Visual Studio, it created a default.aspx page right on the root. Are you hosting in IIS? If so, it's set up to serve up default.aspx by default. But I digress.
Here's how to make it work like you want (mostly):
Create a WebSite, then right-click the site and add a folder named "prjfiles". Right-click that folder and make another named "public". Create another subfolder of that one called "cssimg".
Now, if you want to use the image you mentioned, you'd reference it like this: "~/prjfiles/public/cssimg/error.png" (pathing starting with the root) or "./cssimg/error.png" if you're coming from a page in the public folder (relative pathing).
Really, though, you're doing too much work. Here's how to make it work with less effort:
Create your WebSite, right-click the project and add a folder called "cssimg".
Treat the root as you would the "public" folder- put your pages right there on the root or in subfolders, as needed. You can reference that same image file like this now: "./cssimg/error.png" (relative) or "~/cssimg/error.png" (start from root)
There's also another way to tell the engine where to look for resources, but it's for your css files. Inside the "head" tag, you can add a "style" element (with type="text/css") and inside that you can add something like this: #import '<%= ResolveUrl("~/prjfiles/public/cssimg/styles.css") %>';
Good luck!
If I correctly understood your problem, you're trying to find files which aren't physically stored on a filesystem folder, or stay on a different folder. You can deal with this problems by implementing a UrlRewrite mechanism.
I suggest you to read URL Rewriting in ASP.NET and, after, to take a look into this implementation: A Complete URL Rewriting Solution for ASP.NET 2.0.
If I understand all this correctly (please comment with any correction) right now all your files are together in the root directory and you use <img src="/img.png" /> and it works.
If this is the case, make another directory in the directory the images are in, say call that directory images and put the image files there. now use <img src="/images/img.png" />.
Done.

Can i put URL rewriting http module in a folder?

I am trying to make a generic URL rewrite methods, and i want it portable so i checked this article: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx which is very nice.
But i want to put all my classes, http modules in one folder, then i can just paste this folder in any asp.net website and edit the web.config to point to this http module, thats it, without the need to add anything in the APP_Code as this article teaching.
My question is is that possible? any conc or better ideas?
The ASP.NET runtime only looks by default in a limited number of folders for code files that it compiles on the fly -- App_Code (and its subfolders) is one of them. If you place code in an arbitrary folder, it won't be found.
The usual approach for what you describe is to build a DLL, and then drop it into the web site's bin folder. You would then have a separate project in Visual Studio for building the DLL. Using a subfolder in App_Code is another possibility.
You could also put your DLL into the GAC, which would make it accessible to all sites on a server.
You always can to compile that code into an assembly (.dll), place it inside your /bin folder and to update your web.config file.

ASP.NET: external custom config file in a virtual directory - how to?

I know that there at least two approaches to leverage the web.config file:
using the configSource attribute which was introduced in .NET 2.0 - here is a good blog entry about it.
The file attribute of the appSettings tag which lets you point to an external file with a relative path. Described in the MSDN documentation on the appSettings element.
Now, my problem is that both approaches work well only for physical paths. But I need to address a config file which is in a virtual directory.
Which other method could I use to put my config resources in a virtual directory?
Note: I want to do it this way, because I have multiple instances of my web application on the same server (and that on many servers). To keep deployment easy and clean, I want to keep one directory for all the files (aspx, ascx, images, css, js etc.) and point the web apps in IIS for different customers (=domains, https etc.) to this single directory. In every IIS web I would have a virtual directory called "custom" which points to a different folder for each web.
Update: I'd like to point out that this virtual directory "custom" is not suited to contain an inherited web.config - that web.config would be valid only for the custom folder which doesn't contain aspx/ascx files.
I have the same scenario and after reading you post I realised that asp.net won't let you do this for various security reasons.
Therefore I turned to the OS to find an equivalent to the Linux soft link function which in turn led me to the Junction utility from sysinternals. This can create a directory that is actually any other directory on that volume and asp.net can't tell the difference and so happy loads the config sections that are not actually in a subdirectory of you website. Works for me :)
Virtual Directories can be set as applications, and you can just place another web.config there.
It will inherit any changes from the parent config, and you can add custom settings in it.
I was looking to do the same thing but it did not work, so I decided to do the opposite, as you know the web.config can be inherited, so I pointed IIS to a folder containing the client config (connection string, file path etc) files and the website files i put them on a virtual directory with the rest of the webconfig (where it load dll and other application files needed)
So basically i can use the website files to multple clients and the clients with their own Database connection string and other specific client settings.

Resources