Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server Side Include Problem

Status
Not open for further replies.

SFDWeb

Programmer
May 13, 2005
7
US
Hello,

I'm very new to ASP.NET I am developing an application that uses a couple SSI's. The problem is, the files reside on a web server and I cannot download them to my local drive and add them to my project.

Everything I've tried this far to include them has failed and I end up with runtime errors when testing the application on the localhost.

I've tried: <!-- #include file="/somefile.inc" -->
I've tried: <!-- #include virtual="/somefile.inc" -->
I've tried calling out the absolute path
I've event tried creating a user control.

I'm stumped at this point. How to I make a call from within a table cell to an include file residing on a web server that cannot be physically added to the project itself?

It was so easy in legacy ASP but not so clear cut in ASP.NET.

Any help is appreciated!
 
You shouldn't use include files in ASP.NET (this is a throwback from ASP).

In ASP.NET you should use the object orientated approach so you define a class that will handle all relevent functions. You then just create a new instance of the class and call the function.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Thanx for the reply ca8msm but I'm still stumped.

Even if I create a class I still would have to make a call to the include file to get it to appear in the page.

How do I get it to appear if I'm not supposed to use
<!-- #include file="somefile.inc" --> ??

I guess I'm not understanding how your suggestion solves the problem which is surely due to my inexperience with .NET.
 
Even if I create a class I still would have to make a call to the include file to get it to appear in the page.
No you wouldn't. What you actually do is create a class. e.g.
Code:
Public Class Class1
    Public Function MyFunction(ByVal MyValue As Integer)
        Return MyValue + 1
    End Function
End Class
Then, in your page you create a new instance of your class and call the function e.g.
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim MyNewInstance As New Class1
        Response.Write(MyNewInstance.MyFunction(1))
    End Sub

Does that make sense to you?


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Small type...the class should have read:
Code:
    Public Class Class1
        Public Function MyFunction(ByVal MyValue As Integer) As Integer
            Return MyValue + 1
        End Function
    End Class

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Sorry ca8msm, I still don't see how that solves the problem.

The include file needs to be displayed within a specific table cell and the include file I need to display contains graphics, javascript and calls to more includes so I still don't understand how creating a class with a function in it is going to make the include file execute in the table cell.

But I appreciate the help.
 
I'm showing you how OO works. The idea is to not use any include files. i.e. get rid of them, don't use them, throw them away!

the include file I need to display contains graphics, javascript and calls to more includes
If you want to use ASP.NET correctly then

1) Replace the use of include files with User Controls and Classes (like I demonstrated).
2) Move the javascript from you include file into a .js file.
3) Create a css file and make your tables us this file
4) Replace the "calls to more includes" with calls to new classes that you create to hold these functions

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
You said --

"If you want to use ASP.NET correctly then

1) Replace the use of include files with User Controls and Classes (like I demonstrated).
2) Move the javascript from you include file into a .js file.
3) Create a css file and make your tables us this file
4) Replace the "calls to more includes" with calls to new classes that you create to hold these functions "

That's just it! I don't have access to the include file(s) that I need to include! It resides in the root directory of the web server and I don't have permission to view it, only to call it as an include in my form.

So I can't just copy the code in it and create my own class and own functions.

It's simply an include that all the developers are supposed to use in their applications/pages for purpose of branding.


 
Well as it goes against the principles of OO, I wouldn't like to recommend a solution in which include files are used.

You did say in your original post though, that "It was so easy in legacy ASP but not so clear cut in ASP.NET.". So how did you link to the include file in ASP then as it would exactly the same if you were to do it in ASP.NET.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
In legacy ASP I call the file like this:

<tr>
<td><!-- #include virtual="/somefile.inc" --></td>
</tr>

In ASP.NET if I place the include in the table cell I get the following runtime error:

"Could not find file "c:\inetpub\
The error prevents me from testing the rest of the application functionality.

I can't place the file in c:\inetpub\ because I don't have the file.

Are you beginning to see the dilemna?
 
In legacy ASP I call the file like this:

<tr>
<td><!-- #include virtual="/somefile.inc" --></td>
</tr>
I can't see how the original ASP application (running on your local machine) would be able to find a file that was on a web server somewhere just because you have placed the virtual attribute in the include statement (hence why ASP.NET also has this problem).

I do see you dilemma - you want to use ASP code in an ASP.NET application which is always going to cause you problems. If you have no control over this, then fine, but there are going to be lots of problems, some of which that won't be solved and some that I wouldn't like to offer solutions to as I think that if the company wants you to develop an ASP.NET app, then the provisions to do so should be made available to you.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Well in legacy ASP I could build pages in an html editor so the editor didn't care where the include file lived so when I put the page on the server it would find the file with no problem.

None of that is true in ASP.NET because it has to be compiled so it definately cares whether or not it can find a given file.

So I guess I'm still stuck and I'm trying to do the impossible and that the bottom line is that I can't use the include file in my application. Very frustrating!

Thanks for the help

 
None of that is true in ASP.NET because it has to be compiled so it definately cares whether or not it can find a given file.
That's not true. If it is an include file, there will be a parser error when you try to view the file, but the project will still compile correctly.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top