Classic ASP: Page Reference - asp-classic

I have three pages in Classic ASP:
Root>Login>login.asp
Root>Web>index.asp
Root>Web>Section>index.asp
In Root>Web>index.asp and Root>Web>Section>index.asp I include Root>Login>login.asp:
Root>Web>index.asp: <!--#include file="../login/login.asp" -->
Root>Web>Section>index.asp: <!--#include file="../../login/login.asp" -->
But my problem is:
on Login.asp I do a redirect to Root>index.asp if the session is expired.
RESPONSE.REDIRECT("../index.asp")
works for Root>Web>index.asp but - of course - doesn't works for Root>Web>Section>index.asp because of the "href referencial"
In HTML I do this:
<base href="../../">
Are there any similar solution on ASP or I need to make an IF for each one?

In ASP :
"/" > redirect to the root then the best solution for this problem is simply, put / without ..
RESPONSE.REDIRECT("/index.asp")

Related

ScriptManager globalization issue

I'm having a problem with the asp:ScriptManager not working correctly under SharePoint. I have set EnableScriptGlobalization="true" to be able to use the Sys.CultureInfo object of ASP.NET AJAX, but because of the script is being output in the wrong order, it's not working. The same code works correctly under a plain ASP.NET site, so the issue seems related to SharePoint somehow. Though it did work correctly under SharePoint 2007.
To reproduce the issue, I created this simple usercontrol CultureControl.ascx.
<%# Control Language="C#" %>
Server side culture: <%= System.Threading.Thread.CurrentThread.CurrentCulture.Name %><br />
Client side culture: <script type="text/javascript">document.write(Sys.CultureInfo.CurrentCulture.name);</script><br />
When I include this control on a regular ASP.NET web site .aspx page, and set the culture to sv-SE on the server side, the output is as expected.
Server side culture: sv-SE
Client side culture: sv-SE
But when I put the same usercontrol on a page in a SharePoint 2010 site, set the site locale to Swedish and set EnableScriptGlobalization="true" in the master page, I still get the output
Server side culture: sv-SE
Client side culture: en-US
When I started digging in to this problem, I noticed that the reason was that the script blocks that the ScriptManager outputs are in the wrong order. When EnableScriptGlobalization is set to true, the ScriptManager outputs a script block that defines a __cultureInfo variable, which is then used to initialize the Sys.CultureInfo. This variable has to be defined before MicrosoftAjax.js is loaded, otherwise it will default to en-US culture.
In the ASP.NET site, this works correctly. The __cultureInfo variable is defined first, then MicrosoftAjax.js is loaded from WebResource.axd. But under SharePoint, MicrosoftAjax.js is loaded a lot earlier and the __cultureInfo variable is defined too late.
Does anyone know of a solution or workaround for this issue?
One solution i am doing and its working perfectly. Add the following at the end of your page (Master Page)
<script>
if (__cultureInfo)
{
Sys.CultureInfo.CurrentCulture = Sys.CultureInfo._parse(__cultureInfo);
delete __cultureInfo;
}
</script>
UPDATE: I wrote a wrong solution before, now the above one is properly updated.

Links in master page with tilde URLs give 404 depending on the page

I have a master page with links to other pages in the site. Those links use tilde paths (like "~/dir1/page2.aspx"). On most of the pages in the site that use this master page, there is no problem.
The problem only occurs on a few pages that use the master page. The links are VERY wrong; it tries to use the ~ as part of the link (so they are "http://server.domain.com/~/dir1/page2.aspx").
It's as if it is treating the tilde as a literal under certain circumstances.
Sounds like you're not properly resolving the URLs.
Are you writing ResolveUrl("~/")?
Also make sure that if you use ~/ that your controls are runat="server".
I just had this issue and the answer that worked best for me was to use the asp:Hyperlink control:
<asp:HyperLink ImageUrl="/Images/Logo.PNG" runat=server NavigateUrl="~/Default.aspx" />

Is it possible to include an asp (header) file on an asp.net page?

I have a classic asp website, onto which I am adding an asp.net (.aspx) page. Is it possible to include my existing asp header (header.asp) and footer (footer.asp) files on my aspx page?
I don't want to convert the page to a user control, because those pages include other asp pages with asp code on them.
Thanks
There's a rudimentary way of doing this described at Microsoft support. In a nutshell:
<%# Page Language="vb" AutoEventWireup="false"%>
<html>
<body>
<%
Response.WriteFile ("Yourfile.inc")
%>
</body>
</html>
One thing that may pose a problem for you is that this won't execute any classic asp code that's in your header/footer files, so wouldn't work for that scenario. If that's the case you may need to consider duplicating the content into an asp.net Master Page and maintaining two copies of the content.
As far as I am aware this is not possible as asp.net does not support vb script only full vb.net.
You could use an iframe to hold the classic asp includes, but then you run into problems where you have two separate sessions, classic asp and asp.net as they are not shared.
<div id="header"/>
<div id="footer"/>
$(document).ready(function()
{
$("#header").load("header.asp");
$("#footer").load("footer.asp");
}

ASP.NET ~/ not resolving to "/"

My application paths …
<a runat="server" href="~/Home">
…are resolving to “Home” (not “/Home”). After I rewrite URLs, “/Blah/Blah”, all the ”~/” links are relative to the rewrite: /Blah/Home
Is there a way to force a root to “/”?
Why don't you just write the links relative to the root ('/') instead of '~/', if you're application is not at the root of the domain, then the '~/' links will resolve to the root of the application
If you're sure that, for the links in question you'll always be at a root of "/", then the simplest thing to do is change the <a> so that the href reads "/Home" rather than "~/Home" ... That way asp.net won't parse it and change it to use the App/VDir as its starting point.
If you use standard HTML tags like a, then include the url via
...
or use asp.net hyperlinks:
<asp:Hyperlink NavigateUrl="~/Home" runat="server" ID="HomeLink" Text="..." />
That way, all links will point to the right URL, even when the web application will be installed in a subdirectory.
<% %> is inline coding for asp.net, and <%= %> outputs the content, in that case the result of ResolveUrl.
~/ gets translated in the web controls, as in not Otherwise, you need to use ResolveClientUrl to do that.
For the hyperlink control, it will automatically map correctly for you.

Dealing with relative filepaths in ASP.NET and master pages

This may be a painfully simply question for which I will be mocked but I am having difficulty in using filepaths in master pages. I believe this is because if a page in a sub-directory to using the master page then the filepath is incorrect.
To fix this I need to get the filepath from the root but I can't seem to get it working.
I tried:
<script type="text/javascript" src="~/jQueryScripts/jquery.js"></script>
and
<script type="text/javascript" src="../jQueryScripts/jquery.js"></script>
No luck on either!
Any ideas on how I can tell it to get the filepath from the root?
I'm just assuming by filepath, you actually mean url (or uri, I forget which one is partial).
Without the ~, the first example should work. <script type="text/javascript" src="/jQueryScripts/jquery.js"></script> would cause the browser to request http://www.example.com/jQueryScripts/jquery.js (where www.example.com is your domain).
I believe you need to have runat=server in the <head> tag of the MasterPage for this URL rebasing to work.
<head runat="server">
First off the tilde in front is a asp.net thing for use in server controls and won't work in basic HTML.
Without getting into detailed explanations you could just use a slash (/) in front, and include the web app name if its not the root site.
Or you could put code in your master page for dynamically including scripts, and let it handle the pathing. Like:
public void AddJavascript(string javascriptUrl)
{
HtmlGenericControl script = new HtmlGenericControl("script");
script.Attributes.Add("type", "text/javascript");
javascriptUrl += "?v" + Assembly.GetExecutingAssembly().GetName().Version;
script.Attributes.Add("src", ResolveUrl(javascriptUrl));
Page.Header.Controls.Add(script);
}
The above code also appends the assembly version. I use this mostly for development so my javascript files get updated whenever I build.
You could use the Page.ResolveUrl method to get around this
for example:
<script type="text/javascript" src="<%=Page.ResolveUrl("~/jQueryScripts/jquery.js")%>"></script>

Resources