How to get project URL within the application? - asp.net

I need to obtain my project URL so that I create a link to another section of my site when say for example new content is added I can append this location onto it.
Is there a way I can obtain this address
http://localhost:56672/ or http://mywebsite.azurewebsites.net/

If you are creating links manually you should just use a relative URL instead of absolute. So instead of:
http://mywebsite.azurewebsites.net/some/link/here
Use this:
/some/link/here
The browser will automatically fill in the hostname.
If you are linking to an action method, then you should be using Url.Action or Html.ActionLink.

Related

Loading an iFrame based on a variable URL in Angular 2

I'm trying to figure out in Angular 2 how to do the following
Enter a url into the address bar and load an iframe based on that URL
For instance,
localhost:3000/http://test.com should load a full screen iFrame of test.com
Could anybody provide any reference to this?
There's no any in-box solution in angular package.
But I see you could make it with next steps:
create FrameComponent component that will show iFrame the way you need
configure route to match FrameComponent
Navigate by url and extract path from activatedRoute
add url to iframeSource
profit
But you'll meet some issues - cross origin navigation, not safe url, etc.
One of them could be fixed with DomSanitizer and SafeResourceUrl from #angular/platform-browser.
A made some proof to show what I mean:
https://plnkr.co/edit/9sgwAy?p=preview

Working with iframes with the moovweb sdk

I've created a project with the moovweb sdk and have trouble editing the content within an iframe on one of the pages. For instance, moving a div around inside the iframe doesn't seem to work with the tritium I'm writing. What can I do with tritium to make this work? The domains are different FYI.
Unfortunately, Tritium only allows you to edit the attributes of the iframe itself, not the content within.
This is because the request for content in the iframe is made after the browser constructs the DOM of the main page. Tritium can only intercept the first request for the main page, not the second request for content from a different domain.
I know of two workarounds:
Add the second website as a Moovweb project and you will be able to use Tritium to manipulate the content. Then you can point the iframe of the original page to this new content.
Use JavaScript/AJAX to modify the iframe's content.
However there are implications for production domains... I'm afraid I may have rushed this answer and will update it after I do more research.
If the iframe is on the same origin (http://m.yoursite.com) or on an origin you have in your config.json you can absolutely use tritium! However, maybe not in the way you expect!
So, the iFrame is going to make a separate request to the src attribute's location. If you ensure this request is going through the SDK (by rewriting it) like so:
$(".//iframe[#src]") {
attribute("src") {
rewrite("link")
}
}
Then you can map that url and perform your regular tritium on it!
you need to analyses the src of iframe and need to write mapping in mappings.ts for the url in src. Include proper .ts file in pages folder and start transforming it.

ASP.Net pages relative paths?

I have a website which i run localy and the path on the browser is
"http://localhost:3184/basel/index.aspx"
I have a menu which contains various hyperlinks and one of them is:
//This will evaluate to http://localhost:3184/basel/en/open-account/index.aspx.
The hyperlink will redirect me the page above, After that when i try to click the same link again on the menu, the path of the page is the following:
"http://localhost:3184/basel/en/open-account/en/open-account/index.aspx"
Why is it that the path have duplicated, i have been struggling for a while but can't seem to figure this out, Any solution ?
Try this:
Using the tilde creates an application-relative path.
What is in your code behind? If the A tag is being set dynamically (maybe something like this myHyperlink.NavigateURL += "en/open-account/index.aspx";) then each time the page is loaded the URL will have a new value appended to the end.
Maybe check the code behind to see if this URL is being manipulated there? If you've already done so, my apologies :)
Use Page.ResolveUrl() method. If the relativeUrl have an absolute URL, the URL is returned unchanged. If the relativeUrl have contains a relative URL, that URL is changed to a relative URL that is correct for the current request path, so that the browser can resolve the URL

Image disappear when url route

I am writing a web page to show image (image is dynamically generate by .Net charting) in a web. I have used the asp.net web forms URL routing to navigate to this page. Once I use the URL routing the image appear on the page. Anyway this is working fine for normal page browse.
More than likely your link to the image is using a relative path, and once you introduce routing you are working with a URL structure that appears to be deeper nested in the folder structure than it is.
When linking to the image for display I would recommend using root relative path something like /Images/MyFile.jpg rather than ../Images/MyFile.jpg, or similar.
This way if your route changes, and additional "folders" appear in the route, the link will still work.

Using 1 sitemap but dynamically change the target location of each link

I have a sitemap file in my project. None of the links on this file are contained on our server. They all are located on another project. We need this sitemap to mimic the navigation of the original site.
Right now the url is setup like this:
url-"~/folder a/file.aspx"
What I would like to do is dynamically change the server location of these links. Is there a way to do that?
Basically I don't want to have to hard code the dev.server or the prod.server in the sitemap.
Your best bet is probably to create a custom XmlSiteMapProvider with a "base URL" property that your URLs will be appended to. You can then change your base URL to the appropriate site (dev/prodction).

Resources