To get fully qualified path of application I have wrote a function:
public class Generic
{
public static string FullyQualifiedApplicationPath
{
get
{
//Return variable declaration
string appPath = string.Empty;
//Getting the current context of HTTP request
var context = HttpContext.Current;
//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80
? string.Empty
: ":" + context.Request.Url.Port,
context.Request.ApplicationPath);
}
if (appPath.EndsWith("/"))
appPath = appPath.Substring(0, appPath.Length - 1);
return appPath;
}
}
}
when I use it in <head> tag between <%=%> I am getting different outputs.
<link href="<%= Generic.FullyQualifiedApplicationPath %>/Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="<%= Generic.FullyQualifiedApplicationPath %>/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
html output:
<link href="<%= Generic.FullyQualifiedApplicationPath %>/Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="http://localhost:2093/SourceOne/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
just wandering why asp.net engine sends <%= Generic.FullyQualifiedApplicationPath %> to client.
–NJ
ASP.NET basically treated your inline evaluation as string literal and escaped it. You may try using Databinding syntax <%# %>
then in your code behind, override OnPreRender, and put in the following logic
It is important that the binding syntax is not mixed with other literals, or ASP.NET would treat the whole attribute as string literal.