Reputation: 1257
How can include .asp file inside of html file and have it proccessed besides having to process all html files with asp.
Upvotes: 3
Views: 10531
Reputation: 67
I know this is a old question but for those interested, there is a solution to it if you code it right, i figured out how to with some testing I did. I got a working coded version of it so I know for a fact it works but i'll try to explain it out.
Lets say you have a header, navbar or footer (the usual place of a copyright year/info that Boris mentioned in one of his comments). Yet you don't want to change the .html / .htm file extension of however so many of those files because of the links involved and if other sites link to your website.
Though for Boris its just the footer of each file, easy way to do that is by putting the following in your html files where ever your footer code is placed.
<script type="text/javascript" src="Footer.asp"></script>
That was the first part of it, the next part is using JavaScript within the footer ASP file like so:
var Code ='';
Code+='your html here';
Code+='more html here if needed';
document.write(Code);
You can even put functions above the var and those functions will work with whatever you have in the: Code+='your html here';
Now in that bit of code you might have for example something like: Code+='<form id="UserSignUp" name="UserSignUp" method="post" action="AddUser.asp">';
and you can say for example add users to a database.
But in Boris case it's the copyright year, so in that same Footer.asp file you have a few options. In the Code+='your html here';
you can use the code you made / found that updates it year by year or you can manually update it once per year on just that one file.
Yet it begs the question of, why are you not using JavaScript in the first place for the copyright year with the document.write();
in a Footer.js file instead. Unless your copyright year code is in ASP?
In which case in that Footer.asp file above the JavaScript functions, just add your ASP code such as for example: rsYear("CopyrightYear") = Now
along with the rest of the ASP code that you might need.
While in the JavaScript add something along the lines of:
Code+='<script>document.write("Copyright: <%=rsYear("CopyrightYear")%>");</script>';
Upvotes: 0
Reputation: 316
One of the possible solutions is to change the extension of your page from .html to .asp as it will have no effect on your page and its execution.Then you can include the .asp file normally as we include it in .asp files.
Upvotes: 1
Reputation:
You can change executable extensions, so, if you want, you can make .html executable so that you could include file or do anything else.. Go to IIS manager (run->inetmgr), choose properties of your site, under tab 'Home directory' press 'Configuration..' You can add an extension there and an executable (you can insert the same as in the .asp)
But I don't think this is a best choise :) if it's exetutable, it should be .asp, if it's not - html
Upvotes: 1
Reputation: 2717
I'm not totally sure what you're asking. If you're attempting to include a .asp file into a .html file, I don't believe it's possible. If you change your file's extension to .shtml, then you can put the following line into the HTML file:
<!--#include virtual="path to asp file/include-file.asp" -->
Now, whether or not the ASP would be parsed or the code will be displayed will have to be addressed by someone that understands server parsing better than me.
What would be a better solution is to just include an ASP file into another ASP file. If you want functionality like page-including, then giving your files .html or .shtml extensions will only make it harder to accomplish what you're trying.
Basically, use .asp for files that you want parsed and .html for files that can be served up to the user as-is.
Upvotes: 1
Reputation: 18474
you could use an IFRAME tag...but it's a bit sucky. I'd do what Phantom Watson says.
Upvotes: 3