C# - Is There A Built-in Create An Absolute (fully Qualified) Url From A Relative Path Such As "~/page.aspx" Given The Current URL?
Dec 8, 2010
Scenario is I have a application relative url like "~/path/to/page.aspx?query=string". I need to programatically create a web request to that page and currently using WebRequest.Create. The problem is WebRequest.Create requires a fully qualified url including the protocol/domain/port etc.I have access to the current Request.Url object but there doesn't seem to be an easy way to get just the base url keeping the protocol (HTTP vs HTTPS) as well as any port numbers as well as the path to the applicationI mean all the info there, so if need be I could just take all the parts and combine them but it seems like it might be error prone and it would be great to have something built-in that's well tested to do the job. Page.ResolveUrl gets me almost there, but it's missing the protocol and the domain/port.
View 1 Replies
Similar Messages:
Apr 17, 2010
In ASP.NET MVC how do I get the fully qualified path to my css file by specifying the relative path.
Eg
Url.Content("~/Content/Print.css")
This returns eg "/Content/Print.css"
Where as I want
http://www.mysite.com/Content/Printcss
View 2 Replies
Mar 2, 2010
I have a webpage in ASP.NET 3.5 that will be creating WebControls dynamically. The WebControls that it will be creating will be known by their fully qualified path (ie - System.Web.UI.WebControls.whatever). The reason for this is because I am allowing the user to decide what controls will go on the webpage. Of course, there's more complexity than this, but that is it in a nutshell.Simply put - how do I create a WebControl on a webpage by it's fully qualified path?I realize that the answer will probably end up using reflection, but I have little experience using reflection and I don't want to shoot myself in the foot by making a newbie mistake.
View 2 Replies
Apr 8, 2010
I am Final Year IT Engineering student. I am Doing Content Management System in ASP.net for my college. I have given link on my master page for various pages in the application; where I have specified only relative path of those pages. When I run this project and follow any link it works well for only first time and for second time when I click any link it .net run time environment unable to find the absolute address of that page.
View 2 Replies
Dec 14, 2010
Possible Duplicate: Absolute path & Relative Path
When to use absolute path, relative path and what is the difference between both?
View 2 Replies
Jun 12, 2010
In ASP.NET I'd like to create a link which points to a specific Uri and send this link in an email to a user, for instance something like http://www.BlaBla.com/CustomerPortal/Order/9876. I can create the second part of the Uri /CustomerPortal/Order/9876 dynamically in code-behind. My question is: How can I create the base Uri http://www.BlaBla.com without hardcoding it in my application? Basically I want to have something like:
http://localhost:1234/CustomerPortal/Order/9876 (on my development machine)
http://testserver/CustomerPortal/Order/9876 (on an internal test server)
http://www.BlaBla.com/CustomerPortal/Order/9876 (on the production server)
View 3 Replies
Jun 9, 2010
When I write following code in my view
<% Url.Action("Logon") %>
the mvc framework generates
/Account/Logon ({controller}/{action})
as path.
'/Account/Logon' path is an absolute path. Is there a way to change is to a relative path, like Account/Logon or ../Account/Logon.
Also, when I use the Html.Beginform(), the mvc framework generates <form action="/account/logon"..., I want to change this to <form action="account/logon"...So, problem is that I want relative paths instead of absolute path.
View 6 Replies
Sep 9, 2010
I am really surprised that there is no native .NET method to get an absolute url from a relative url. I know this has been discussed many times, but never have come across a satisfactory method that handles this well. I think all I need left is to auto choose the protocol instead of hard coding it (http/https). Anything else I am missing (caveats, performance, etc)?
public static string GetAbsoluteUrl(string url)
{
//VALIDATE INPUT FOR ALREADY ABSOLUTE URL
if (url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
return url;
}
//GET PAGE REFERENCE FOR CONTEXT PROCESSING
Page page = HttpContext.Current.Handler as Page;
//RESOLVE PATH FOR APPLICATION BEFORE PROCESSING
if (url.StartsWith("~/"))
{
url = page.ResolveUrl(url);
}
//BUILD AND RETURN ABSOLUTE URL
return "http://" + page.Request.ServerVariables["SERVER_NAME"] + "/" + url.TrimStart('/');
}
View 6 Replies
Oct 13, 2010
i am fetching image using webservice into dataset and displaying for that its to be get worked after deployment i have done following line of code but its still not able to display the image after deployment
String imageName = row["ImageName"].ToString();
String physicalPath = HttpContext.Current.Request.Url.AbsoluteUri.ToString();
String imagePath = physicalPath.Substring(0, physicalPath.LastIndexOf("/",
StringComparison.OrdinalIgnoreCase) + 1) + imageName;
View 3 Replies
Apr 4, 2011
I have a code to get the list of OUs within a domain. Now this just lists all the OUs and does not give any way to distinguish between an OU and a sub OU.
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=organizationalUnit)");
foreach (SearchResult temp in mySearcher.FindAll())
{
OU_DownList.Items.Add(temp.Properties["name"][0].ToString());
}
Is there a way i can get the fully qualified name of an OU? Something like this for a sub OU:
CN=Computer1,OU=Department 101,OU=Business Unit #1,DC=us,DC=xyz,DC=com
View 2 Replies
Jan 22, 2010
Suppose I have a resource located in ~/Resources/R1.png This resource's relative URL will vary depending on the current address.
For instance: If I'm at www.foo.com/A/B/C/D.aspx and the www.foo.com/A is the root path including Virtual Directory, then the path relative to the current address of ~/Resources/R1.png is ../../../Resources/R1.png
How can I get this relative path?
EDIT:
I want a web path that I can use in a web page, not a server path.
View 4 Replies
Mar 28, 2011
i want to get the fully qualified url to a resource in ASP.NET.
e.g.:
<LINK rel="shortcut icon" href="<%=GetFaviconPath()%>">
with the code-behind file right now containing:
private String GetFaviconPath()
{
String url = System.Web.VirtualPathUtility.ToAbsolute("~/Images/clock.ico");
return url;
}
Unfortunately this doesn't work because it doesn't return the fully qualified path, only the path relative to the server:
/Employement/Images/clock.ico
Internet Explorer requires a fully qualified url, e.g.:
[URL]
How can i get the fully qualified path to a file? i've tried VirtualPathUtility and i'm all out of ideas.
View 2 Replies
Nov 7, 2010
I have a generic class and I want to generate a URL when given the controller and action values. The most obvious method is Html.Action(controller, action), but this can only be called within a View. I tried adding 'using System.Web.Mvc;' to my class, but this doesn't give me the Action() method. I also tried converting this to an HtmlHelper class, but again no luck.
How do I generate a fully qualified URL within a class using the controller and action names?
View 1 Replies
Aug 25, 2010
I have a page on my site, for purposes of this example lets say [URL]. On Default.aspx I have a user control called MyControl.ascx which lives in /Controls/MyControl.ascx. So the tree looks something like this
[code]...
Whenever I place a HyperLink control on MyControl.ascx and specify a NavigateUrl, this path is relative to the control, not the URL of the page. So for instance if in NavigateUrl I specified "AboutMe.aspx", the URL would be rendered as [URL] instead of [URL]. Is there any way I can make this relative to the page URL? I've tried the solution here: [URL] but it didn't work for me.
Edit
To clarify, I'd like this to be generic enough so that if I didn't know what the path was the solution would work. So I don't really want to harcode "~/Pages/Default.aspx" in the NavigateUrl
View 2 Replies
Feb 12, 2010
Question about paths while working in Visual Studio. In my master page I have some paths to load css files as well as javascript files.
My first question is if I use relative paths, should the relative path be from the location of the master page file? For example if I keep all my master page files in a folder off the site root called MasterPages should I assume that is the starting point for my relative paths to load the css files? If that master page is used to wrap an aspx file several directories down the tree is the hard coded relative path still valid?
Second question, is there a way to use absolute paths so that everything works on my local machine as well as when I move the files up to the webroot? For example my app path on my local machine may be localhost/myappdir/default.aspx but when i move the app to the server there is no myappdir and the default.aspx is in the webroot. I do not want to have to change paths in the files after they are moved up to the server. currently I have;
src="<%= VirtualPathUtility.ToAbsolute("~/lib/css/style.css")%>"
but this way Visual Studio cannot find the css file to update intellisence
View 4 Replies
Jul 22, 2010
I have got a master page(Project>>MasterPages>>MainPage.master) and some images in that page with some path like "../../Images/bg_main_menu.png".
I refer this master page in two forms. One of those form is oresent in the path :
Project>>Forms>>Form1.aspx and the other one is : Project>>Forms>>NewFolder>>Form2.aspx
Now for Form2.aspx the image is not getting loaded.
I tried the image path with "~Images/bg_main_menu.png". But it is not working.
View 2 Replies
Apr 4, 2010
I have this master page, that uses a few .js files and a flash animation.
the <script> and <object> tags that are used to embed these in the page take in relative paths as src. However, since the pages .aspx, i'll need to convert these into tilde paths, ie. somehow change the relative paths to tilde path (is this the absolute path?), so that i can use the master page in any of my pages in subfolders as well. if this question has been posted b4, kindly give me a link... i've not been able to find a solution.
View 3 Replies
Jan 23, 2011
I just want to position the first label in a position on the left and then the start position of the second label at a position. I can't use relative because of the different lengths of the strings. But I the absolute will not work. I tried putting position relative in the cssclass phoneCostsStyle but it doesn't work.
[code]....
View 3 Replies
Jun 24, 2010
i have created aspx pages with left navigation menu control... when ever mouse over the menu control some elements disappearing... that disappeared elements having position:relative CSS this problem having IE6.0 and IE7.0only
View 1 Replies
Feb 8, 2011
I've added a subarea to my sitemap in CRM 4.0, and for absolute URLs it works as expected. However, for relative URLs it does not. The page in question is internal and is accessed through:
http://localhost/ISV/<orgName>/Account.aspx/ExternalDocumentList
However, I would prefer writing this in sitemap:
/ISV/<orgName>/Account.aspx/ExternalDocumentList
When this is expanded, CRM/IIS rewrites it to:
http://localhost/<orgName>/ISV/<orgName>/Account.aspx/ExternalDocumentList
For reference, here is the sitemap addition (which doesn't work):
<SubArea Id="custom_documentHistory" Url="/ISV/<orgName>/Account.aspx/ExternalDocumentList">
<Titles>
<Title LCID="1033" Title="Document History"/>
</Titles>
</SubArea>
How can I link to this page relatively?
View 1 Replies
Jun 21, 2010
I created a survey in vb.net where results are stored in an Excel file.Locally I can access and update the data of the file, but if I put online can not correctly access the excel file.How can I determine the absolute url of the file so, when a user submits the answers they can be inserted correctly in the excel file? Currently I use this to determine the location of the file:
Dim LocalizacaoFicheiro As String = String.Concat(Server.MapPath("."), "RespostasQuestionario.xlsx")
View 3 Replies
Aug 17, 2010
In ASP.NET MVC 2, how can I get the absolute path to the Content folder from within a model?I'm trying to check for the existence of a file by calling IO.File.Exists. So, I need to convert the "~ContentisFile.png" relative path to an absolute path.I tried getting the application's directory path by calling My.Application.Info.DirectoryPath but that returned some temporary folder that doesn't contain the Content folder.
View 2 Replies
Feb 14, 2011
i want to know that from which pages my current page has been called in ASP.net As for example I want the track of page named "hero.aspx" and it has been called from "Zero.aspx" and "Zero.aspx" has been called from "one.aspx" So i want output as whole page called hierarchy.How can i get this in asp.net
View 3 Replies
Sep 9, 2010
How do you calculate a relative path in ASP.NET MVC?
View 2 Replies
Sep 27, 2012
I have a Datalist where I want to retrive Images from a folder and I have done URL rewritting so Images is not displaying when I write something like this:
<asp:HyperLink ID="HyperLink1" ImageUrl='<%# Bind("Product_Image", "~/ProductImages/{0}") %>'
NavigateUrl='<%#"http://localhost:49524Mysite/Product/" + stringToBase64String(Eval("ProductID").ToString())%>' CommandName="IMG" CommandArgument='<%# Eval("ProductID")%>' runat="server"></asp:HyperLink>
[CODE]..
I don't want to write whole URL.
View 1 Replies