Is there a built in method to handle urls like Default.aspx/mycontent or do I need to handle it myself by taking the url and stripping of the file's path?
I have tried searching for it but haven't been able to find anything.
I'd like to handle .aspx/parameters and am not looking at Mod/URL Rewrite.
You could either write an url rewrite handler, use ASP.NET MVC routing in your webforms application, or use ASP.NET MVC instead of webforms.
Take a look at ASP.NET MVC. This framework obviously goes far beyond just "user-friendly" URLs, but it does also handle this as a byproduct.
Or you could just write a HttpFilter...
If you want you're app to do "friendly urls" then surely you would want to avoid ".aspx" appearing in the URL? Have considered ASP.NET-MVC or at least the routing elements of it.
You can parse out the appended "folder" using the Request.Url.Segments Array:
this.Response.Write(this.Request.Url.Segments[this.Request.Url.Segments.Length - 1]);
Then use Server.Transfer or render whatever you like. You will often have problems with relative paths and such for CSS and the like.
Related
A very long title, sorry for that.
I'm looking for your input on the best way to support localization in an ASP.NET MVC 5 project in which i would like to pass the locale as part of the querystring. This way it would be easy for users to share a link to website and also pass the correct locale as part of the link.
If this would be done using, for example cookies, the user would pass a link but the page might be in a different language for the person who receives the link. I don't think that that is very nice.
The solution i currently use (http://afana.me/post/aspnet-mvc-internationalization.aspx) does not work nice with incorrect urls and just keeps loading the same page in loop. There is a lot of information on the web and i already went through a lot but i would like to know what is most commonly used and really works well.
As a bonus i would like the solution to work with attribute routing as my current solution doens't play nice :(
you can use resource files for that, the current culture is in the current thread of the web request, so no need to pass it in the querystring but it can be done;
have a look at this live demo: http://prodinner.aspnetawesome.com
you can download/read pdf about it here: http://prodinner.codeplex.com
you can see there that you can change the language using the dropdown;
in Global.asax.cs Application_BeginRequest, there's already code in there related to language, it reads a cookie now (or it's absence), you can make it read the querystring
Ok. I hope it's a right question and title.
I'm totally newbie to asp.net and c#. I've been searching the answer for days and got nothing. So i think this is the best place to ask this question.
this is my current URL
http://localhost:7474/mywebsite/ProductDetails.aspx?Category=CSR&artID=36&alias=support-for-central-jaya-and-yogyakarta-earthquake-disaster
I Want to make search engine friendly url. Can I make above URL to
http://localhost:7474/mywebsite/ProductDetails/CSR/36-support-for-central-jaya-and-yogyakarta-earthquake-disaster
FYI I'm not using MVC.
Yes, you can.
Take a look at RouteCollection.MapPageRoute for details but roughly you need the code below:
routes.MapPageRoute(
"ProductDetails",
"/ProductDetails/{Category}/{artID}/{alias}",
"~/ProductDetails.aspx");
However artId and alias cannot be in the same segment. They need to be separated by a slash (/).
The other difference is that you need to grab the parameter values from RouteData instead of querystring so instead of:
Request.QueryString["Category"]
you do:
Page.RouteData.Values["Category"]
ps: I did it from the top of my mind so it might not compile
May be you can try URL Rewriting. That would be an ideal choice to implement this with no code change at all. And use regular expression to extract values from the url to bounce the values to original aspx page.
http://www.iis.net/downloads/microsoft/url-rewrite
Yes, we can create search engine friendly URL using ASP.NET routing feature. This blog post have an example of URL routing -
http://newapputil.blogspot.in/2013/12/aspnet-40-web-forms-url-routing.html
When the path refers to the actual folder structure and points to the page it's not a problem, i.e. "/Default.aspx/MyMethod", however if "/" brings up "Default.aspx", then "/MyMethod" means something different. Is it even possible at all?
A possible solution, and probably a better one, is to use a web service, which is what I'm using at the moment.
You can add the following:
PageMethods.set_path('/yourpage.aspx');
I found this solution here
I would really like to disable the rendering for the form tag. Basically asp.net will be providing read only pages which should be very clean. i.e, no form tags required
Take it out of the markup then. I don't think it's required if you're only providing read-only access. I'm able to create straight .aspx files on the web server without the form tag, and they work fine. Don't expect your postbacks to work, though.
Have you looked into ASP.NET MVC? It is designed for just this kind of thing...
ASP.NET WebForms does not work well without the main form (ViewState, PostBack, etc. will fail horribly). I think you may be using the wrong tool for your problem.
We have some read-only pages in a system, and we simply fetch the data from our DB as XML and apply an XSLT stylesheet to this. Might be overkill for you however.
Alternatively, why not just remove the tag? Or use an HTML page?
My Silverlight application, using the navigation framework, has very pretty endings to its URLs, due to use of the URI mapping it does. But the front end still looks nasty, like:
http://server:port/SilverlightPage.aspx#/uri-mapped-portion
How can I get the "SilverlightPage.aspx#" portion to look nicer, preferably removing the ".aspx#"?
You could use URL routing which is available as part of ASP.NET MVC or regular ASP.NET
http://msdn.microsoft.com/en-us/library/cc668201.aspx
Edit: To answer your question in the comment:
I haven't worked with this myself, but if you look at the "Using routing with WebForms" section, it should explain it in detail. From what I gather you could use
routes.Add("SomeRoute", new Route("SilverlightPage",new CustomRouteHandler("~/SilverlightPage.aspx")));
You could use the default page instead of SilverlightPage so that it would be just:
http://server:port/#/uri-mapped-portion
Another way to get prettier pages is to use something like ASP.NET MVC which has pretty urls also. Then you could have something like:
http://server:port/Silverlight/App1/#/uri-mapped-portion