How to modify front of URL in Silverlight Navigation app? - asp.net

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

Related

Adding ASP include into HTML

Is there any way to use ASP or ASP.NET to use an include of a HTML in another HTML file? Similar to the way that you can use an include with PHP with HTML and the AddType handler in .htacess?
I am trying to find a better way to update some navigation but the site sits on a windows server that doesn't have PHP installed on it.
There are a number of options available for you to use the first one I would mention is Master Pages if you going to use asp.net.
ASP.NET MVC uses layouts with the Razor view engine so you can control the page a bit more, I really like the MVC way of doing things as it keeps things simple in terms of your functionality and presentation.
Another option is the server side include (this is old fashioned and not really good):
<!-- #INCLUDE FILE="includeMe.html" -->
If you wanted to keep it as an html page you could 'hack' around in IIS to make html pages work with SSI but it is not a very good way of doing things.
Another way of providing information is by using jQuery to include snippets of html for your page to use, something like this, (sorry I haven't tested):
$("#destination-container").load("sourcepage.htm #content-in-this-page");
Again this is probably not the best way of doing things but you can use it for quick results.
My advice is to create a main page, whether it be a master page or a variation of one if you decide to go the MVC route then use PartialViews or something similar.
And of course look at the link Alex K provided: ASP.NET equivalent of server side includes
If the parent/containing code file has a .asp extension then you can use the following code to include another file.
<!-- #INCLUDE FILE="myfile.htm" -->

Something like Smarty in ASP.NET?

Recently, I was working with PHP.
In PHP we have a powerful template engine like Smarty.
Do we have something like Smarty in ASP.NET ?
Quick google search :
Try one of these :)
http://csharp-source.net/open-source/template-engines
Well, you could argue that all ASP.NET webform pages are similar to templates, as they don't need to (and usually don't) have any application logic within the .aspx pages (it all goes in the codebehind). However, you might find that ASP.NET MVC is even more like what you are familiar with. ASP.NET MVC supports a number of view engines, too.
Have you tried Dotliquid?
It's old but still working great with webforms. You can even have User Controls loaded dynamically that use Dotliquid templates to present data from a database or a webapi, giving you the possibility to change the presentation layer by only editing html mixed with Liquid Language (not fully covered).
Check it out at http://dotliquidmarkup.org/try-online
Liquid Documentation at https://shopify.github.io/liquid/

Can you determine the name of the route followed from your webforms page?

I have a ASP.NET 3.5 webforms project I have enabled routing over.
I also have in the project a number of controls doing different things based on what page they are currently being shown in. It would seem that the most straightforward way to control this different behavior is to discover which route was used to load the page and then do things according to that.
However, I can't seem to find a way to discover the route bar looking at the actual request URL and running a regex over it which isn't great. Does anyone know a way to look it up some other way?
Update: there still doesn't appear to be a way to do this in ASP.NET 4.0. Hopefully someone else has figured this out?
It looks like Phil Haack has answered this question in a blog post on his site: http://haacked.com/archive/2010/11/28/getting-the-route-name-for-a-route.aspx
In a .NET 4 webforms app, I used this to determine the route definition.
string myOperation =
((System.Web.Routing.Route)(Page.RouteData.Route)).Url;
//string has value "Stop" or "Start"
Let's say your routes are like so:
routes.MapPageRoute("StopEmailAlerts",
"Stop/{SomeToken}",
"~/Emailing.aspx", false);
routes.MapPageRoute("SendEmailAlerts",
"Start/{SomeToken}",
"~/Emailing.aspx", false);
I posted a couple of simple extension methods you can use to get/set the route name on this post. Seems simpler (to me) than Haack's solution.

Asp.Net Url Handling

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.

MVC + Templates

I am working on a system that gets templatse dynamicly, they contain tags like {{SomeUserControl}} {{SomeContent}}
I was wonder how I could use MVC to render those templates and replacing the tags in the best possible way as the templates will be edited via a web front end, and the content / macros will be create from the same web front end.
You might wanna take a look at maybe using another view engine, here are some examples.
NHaml
Spark
NVelocity
Brail
I'm sure there are many more but these are the ones I could think of.

Resources