Geeks With Blogs
C# ASP.NET UTILS Programming blogus :-)
During the development I faced this problem, but because I have no time to spend to see how to accomplish this, I met for simplicity in my web.config file a key with the right link. But now I have some time to revise the code and adjusted it. The situation is the following: on one server the application is configured to use the following URL in IIS


on another server :

Now how to accomplish this without using a key in web config file where is stipulated the correct URL address.
The solution is pretty simple, I solved it like this:

string requestedPage = Request.Url.Scheme + "://" + Request.Url.Authority.TrimEnd(Convert.ToChar("/")) + ResolveUrl(LinksWebApp.Information);

this also may be used in aspx, for example:

<script type="text/javascript">
window.location='<%=Request.Url.Scheme + "://" + Request.Url.Authority.TrimEnd(Convert.ToChar("/")) + ResolveUrl(LinksWebApp.Information);%>';


public static class LinksWebApp
    public static string Information = "~/Information.aspx";

1) I used the syntax :
   instead of
  not because I love conversions :-), but it suits the case when we are using this syntax in the js like with window.location='...';
2) You may adjust with string.Format and other techniques to avoid string invariation, but for simplicity I showed you this  simple code. Posted on Wednesday, November 26, 2008 2:05 AM How to ASP.NET C#? | Back to top

Comments on this post: Get URL from code behind

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Diadiora Alexandru | Powered by: