I need to know that,how we can get the current url path (e.g. http://www.mywebsite.com/) in asp.net.
I found that java have the request.getContextPath() to get that.
Even in dot net we have this,
System.Web.HttpContext.Current.Request.UrlReferrer.Host
System.Web.HttpContext.Current.Request.ApplicationPath
Is there any other ways that will gives the same result.
I am also interested to know how I will use the code in aspx page.
cheers.
I believe what you want is the HttpRequest.AppRelativeCurrentExecutionFilePath Property
The property gets the virtual path of the application root and makes it relative by using the tilde (~) notation for the application root (as in "~/page.aspx").
Could context.Request.Url.ToString() do the trick your looking for?
context.Request.Url.ToString()
returns: "http://localhost:52550/myapp/somepage/"
I got this :)
http://<%=System.Web.HttpContext.Current.Request.UrlReferrer.Host+System.Web.HttpContext.Current.Request.ApplicationPath%>/page.aspx
cheers :) :)
Related
I have a dynamic web app built using DotNetNuke that uses the following url format:
/SeoDummy.aspx?template={VAR1}&keywords={VAR2}
My user friendly url format is like this:
http://domain.com/.{VAR1}/{VAR2}
I am really terrible with REGEX and need to somehow detect when the user friendly url is requested and rewrite it with the dynamic web app url. I have tried the following, but It is not catching it on the site, it is just 404'ing:
.*/^([^/]+)/([^/]+)/?$
I am sure you that know regex will find my attempt silly, but regex is my kryptonite!
Thanks for any help that can be offered.
Since you are using some custom url,I guess regex would be better than using URI class
In your regex you have misplaced ^..The regex should be
^https?://domain[.]com/[.]([^/]+)/([^/]+)/?$
I have not tested this, but give it a shot and tell me how it works out:
domain[.]com/\.([^/]+)/([^/]+)/?$
It looks like you had it mostly right except for the first carat, marking the beginning of the string... which is impossible since you specified .* right in front of it! Also you missed the period in front of {VAR1} (unless that is a typo?).
I also wouldn't put .* at the beginning because then you could be capturing VAR1 = domain.com, VAR2 = something that is actually VAR1
If you want to become immune to your kryptonite, then this website is really good for looking up stuff:
http://www.regular-expressions.info/reference.html
I have a URL say /Registration/GetName.aspx/?language=English
When i click on a Asp.net Button on the same Page and say Response.Redirect("CheckLoginName.aspx");
It gives me a weird URL
/Registration/GetName.aspx/CheckLoginName.aspx
What should i do
Please Help?
You should use "~/" inside your Redirect
So your code will look something like this
Response.Redirect("~/CheckLoginName.aspx");
Hope this helps
You should remove the trailing / before the query string, since it serves no purpose. Your URL should be /Registration/GetName.aspx?language=English. Another option is to have Response.Redirect("../CheckLoginName.aspx"); This should also work.
I think a solution using a relative path is better, since it is location independant. If you move these two files to another URL, there will be no need for code changes.
I want to remove the Querystring part from my Request.UrlReferrer.AbsoluteUri before the Redirect in C#.
For example, if you have got your
Request.UrlReferrer.AbsoluteUri = "http://localhost:8080/english/index_2011.aspx?logout=true"
Now I want to
Response.Redirect(Request.UrlReferrer.AbsoluteUri) without QueryString part (?logout=true")
Please suggest using C#
use Request.UrlReferrer.AbsoluteUri.ToString().Split('?')[0]
This should do the trick for you.
A cleaner way would be
Request.UrlReferrer.GetLeftPart(UriPartial.Path)
Meaning I want everything up to the path. It should return
"http://localhost:8080/english/index_2011.aspx"
Response.Redirect(Request.UrlReferrer.AbsoluteUri.Substring(0,Request.UrlReferrer.AbsoluteUri.IndexOf('?')));
EDIT
In fact, you can actually use:
Response.Redirect(Request.UrlReferrer.AbsolutePath);
Check it out on MSDN.
So I have an interesting problem here. I am using URL Routing to mask the URL but I want to take the spaces out.
For example:
/sanjuan/ but in the database it's San Juan.
An error is thrown when I type it in because clearly theres a space in the DB.
I don't want it conjoined in the DB though.
How can I accomplish this. I just need some ideas to look into.
What rob described is called slugging.
Have a look at this:
http://predicatet.blogspot.com/2009/04/improved-c-slug-generator-or-how-to.html
you could replace the space with - when rewriting the url, and change back the - back to space when reading it.
I'm facing a strange bug.
Page.ResolveUrl("~/myPage.aspx?param=valueA:valueZ");
And it just not work, visibly cause of the ':'.
When I mean does not work I mean on a site like this:
http://myMachine/myVirtual/default.aspx
If I click on a link containig the code before, i get:
http://mymachine/MyVirtual/~/myPage.aspx?param=valueA:valueZ
Anyone knows how to make it works ?
thx
Replace your ':' with '%3A', not sure if this is the only fix but it is the first thing that jumps out at me.
This is because the : character is a reserved character. For more info on reserved characters you can take a look at this site
It's because the : character is reserved. You need to encode it as %3A...
For multiple value passing, use this: ASP QueryString Collection