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.
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 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 :) :)
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
I'm trying to retrieve the value of myID from my URL.
I'm testing this using <%=Request.QueryString["hotelid"] %>.
It only works the first time the page is loaded either in a new browser, or if my project has been rebuild.
My URL string is typical: http://my/path/to/site/?hotelid=2.
If I try <%=Request.QueryString %>, I'm also getting other values as well. Values I do not see inthe URL string.
What am I missing here?
Update:
Using <%=Request.RawUrl%>, I get the following results:
/Util/NotFound.aspx?404;http://localhost/en/Tjenester/Hotellguiden-2/Hotel-informasjon/?hotelid=3
I have NO idea what the /Util/NotFound.aspx?404 is or where it comes from.
My URL looks like this:
http://localhost/en/Tjenester/Hotellguiden-2/Hotel-informasjon/?hotelid=2
Update 2:
I'm currently investigating if it is EPiServer CMS that is using some kind of caching.
Update 3:
I have solved it. EPiServer is using EPnCachePolicyTimeout which isset to 1 hour. Setting this to 0 (zero) solved my problem.
Sometimes is really helps just writing aboutthe problem here, talking "aloud" about it and voila :)
You need to turn off caching or add your parameter names to the config attribute httpCacheVaryByParams or overwrite the custom caching key method and make it diff on every querystring parameter.