ASP Routing Be Used To Create "clean" URLs For .ashx Handlers?
Jul 29, 2010
I have some REST services using plain old IHttpHandlers. I'd like to generate cleaner URLs, so that I don't have the .ashx in the path. Is there a way to use ASP.NET routing to create routes that map to ashx handlers? I've seen these types of routes previously:
// Route to an aspx page
RouteTable.Routes.MapPageRoute("route-name",
"some/path/{arg}",
"~/Pages/SomePage.aspx");
// Route for a WCF service
RouteTable.Routes.Add(new ServiceRoute("Services/SomeService",
new WebServiceHostFactory(),
typeof(SomeService)));
Trying to use RouteTable.Routes.MapPageRoute() generates an error (that the handler does not derive from Page). System.Web.Routing.RouteBase only seems to have 2 derived classes: ServiceRoute for services, and DynamicDataRoute for MVC. I'm not sure what MapPageRoute() does (Reflector doesn't show the method body, it just shows "Performance critical to inline this type of method across NGen image boundaries"). I see that RouteBase is not sealed, and has a relatively simple interface:
public abstract RouteData GetRouteData(HttpContextBase httpContext);
public abstract VirtualPathData GetVirtualPath(RequestContext requestContext,
RouteValueDictionary values);
So perhaps I can make my own HttpHandlerRoute. I'll give that a shot, but if anyone knows of an existing or built-in way of mapping routes to IHttpHandlers, that would be great.
View 4 Replies
Similar Messages:
Mar 24, 2011
I'm using ASP.NET 4 and the routing engine. In my Global.asax I have something like this.
routes.MapPageRoute(
"Items",
"manager/items",
"~/Manager/Item/Items.aspx"
);
Is writing a link this this acceptable?: <a href="/Manager/Items"></a> Should I be using the <% %> tags and code within to retrieve the route name, "Items" in this case?
View 1 Replies
Mar 1, 2010
What is the Difference betweeen axd and ashx handlers.
View 3 Replies
Mar 29, 2010
How would you accomplish these in ASP.NET Webforms 4.0 Routing;.aspx pages should not be accesible directly, pages should be accesible only with routes,
Start page should be "/" or "/home" or something else, but not "Default.aspx".
View 2 Replies
Jan 19, 2011
I keep running into problems with URLs and routing. Couldn't find an answer on SO. I would like to manage all of my urls/links in a single place. This is for my C# MVC code and the js/jquery ajax code. These urls are scattered throughout my application. Moving to a production server needs some fixes and I don't like the fact that I need to look for all of the occurrences in the application. I don't mind fixing this once - but I would like to do it only once. how to manage all of these links/urls as a group
View 3 Replies
Jul 8, 2010
VS 2008 - create event handlers in C#? but i cant get this:
View 19 Replies
Feb 23, 2011
how to create and configure custom handlers in IIS5.1 and also about mapping the extensions in IIS5.1....?
View 1 Replies
Nov 18, 2010
I am creating a hierarchial grid dynamically. I was able to add a gridview within a gridview. Now how can I create the gridview's rowcreated event handler programatically? I need it to be dynamic, depending on the number of levels of hierarchy I will add gridviews and their events. How can I do it?
the event names will be dynamic like GridView*_RowCreated.. where * will replace by a number of gridviews.
View 2 Replies
Jun 3, 2010
i have a website that generates urls dynamicly.(?Department=1&Category=4&Page=2) then i rewrite the url to (Phone-d1/Sony-Ericsson-c4/)
I have hunderds of products so how do i create a sitemap for this, or should i doit only for the Departments, if so how would i do it.
View 2 Replies
Jul 19, 2010
I have a website that's in Classic ASP on a hosted server. I'd like to be able to create some "virtual" pages so I can specify google-friendly URLs that translate to ASPs [URL] this_is_the_help_page instead of [URL]admin/helpsubsystem/help.aspx?current_user etc As the server also supports ASP.NET - could I use an HTTP Handler to intercept these calls and do any necessary translations?
View 1 Replies
Nov 16, 2010
i have a function that pulls URLs from various web resources. needless to say some are full valid URLS and some are relative as per the HTML of the page. below is my asp.net/ c# logic i derived for examining the URL and then generate a full usable URL from whats pulled from the site...
NOTE:
origianlurl is the full url of the first searched page, and relativeUrl is a url found within the searched page (it can be a full www.site.com or a /contactus.html)
private string ResolveRelativePaths(string relativeUrl, string originatingUrl)
{
if (relativeUrl.StartsWith("http") || relativeUrl.StartsWith("www"))
return relativeUrl;
if (relativeUrl.StartsWith("/"))
{
//get main url something.com
[code]...
View 1 Replies
Nov 12, 2010
How to create event handlers for Composite Controls. I have created a composite control with label, textbox and button. Like this
[code].....
Now how to write the code once a event fires like text changed or click.
View 1 Replies
Jul 27, 2010
i have a product page that can potentially take in the following optional query string params:
Category, OrderBy, Page
How do I create my route so the urls show up like this:
Products/Category/Electronics
Products/Category/Electronics/OrderBy/Price
Products/Category/Electronics/OrderBy/Price/Page/1
basically, im trying to not use the ? for my query string params.
View 1 Replies
Jul 20, 2010
I tried everything I could find, but still does not work on IIS routing.
View 2 Replies
Dec 12, 2010
I am using:
ASP.NET 3.5 SP1 with Web Forms Routing thru Global.asax (System.Web.Routing and RegisterRoutes)IIS 7
Everything is working fine in my local machine, but it gives the following error in my hosting environment:
Could not load file or assembly 'System.Web.Routing, Version=3.5.0.0, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I did everything inside my web.config file mentioned in the following link:
[URL]
But I am still getting the above error.
What else am I supposed to do fix the error?
View 1 Replies
Feb 22, 2011
I have a Web application where i have added a reference to a RESTful WCF. I got the WCF url Routing to work in my webapplication by adding Inherits="RestService.Global" to the Web applications Global.asax.
<%@ Application Codebehind="Global.asax.cs" Inherits="RestService.Global" Language="C#" %>
But then i tried to create url Routing for the Web application and it does not work with the Inherits="RestService.Global" in the Global.asax. If i take it away it works fine. Is there a correct way to do this.
View 1 Replies
Jan 31, 2011
I'm trying to create my own CMS and I've gotten a little bit stuck at the stage of URL routing.
I want clean URLs without extensions and I'd like to be able to create and modify them in a web based interface without any messing around with IIS or actual files.
I've seen how to create a static route, but for that I need to go into my Global.asax file and manually add it.I would like to have all of these routes stored in a database so that I can easily modify them later.
Does anyone know how this can be achieved?
Just for extra information, I will be attempting to create a feature so that if a path exists, but is later changed, a 301 redirect is created to the new URL, is this also possible? (My first problem is the main issue, but thought I might ask this as well just in case it makes a difference)
View 2 Replies
Sep 2, 2010
How to handle asp.net mvc routing along with asp.net webform routing. I have merged my mvc app into my existing web application. In my web application i have implement routing as below:
routes.Add("View Product Details", new Route("Product/{City}/{Manufacturer}/{Name}/{ProductID}/{*ProductType}"));
Similarly i have implemented routing in mvc as below
routes.MapRoute("Product Details",
"Product/{City}/{Manufacturer}/{Name}/{ProductID}/{ProductType}",
new
{
controller = "Home",
action = "ProductDetails",
City= UrlParameter.Optional,
Manufacturer= UrlParameter.Optional,
Name= UrlParameter.Optional,
ProductID= UrlParameter.Optional,
ProductType= UrlParameter.Optional
});
How to handle both pages, as one is custom web form while other is asp.net mvc view?
View 1 Replies
Aug 24, 2010
I'm considering to host WCF Rest Service that i've built on IIS 7. The URL to access my service will be something like
[URL]
Recently, i've been looking to some REST API implementation with a clean URL like Yahoo API
[URL]
I'm wondering what will be the best WCF host environment (e.g. Windows Service) or any solution (e.g. URL rewrite module) considering that I dont want to have application name and .svc in my URL so that I can have a completely clean URL for my REST API
View 2 Replies
Jan 19, 2010
I'm using asp.net/C# and I'm looking to create unique(?) uris for a small CMS system I am creating.
I am generating the uri segment from my articles title, so for example if the title is "My amazing article" the uri would be www.website.com/news/my-amazing-article
There are two parts to this. Firstly, which characters do you think I need to strip out? I am replacing spaces with "-" and I think I should strip out the "/" character too. Can you think of any more that might cause problems? "?" perhaps? Should I remove all non-alpha characters?
Second question, above I mentioned the uris MAY need to be unique. I was going to check the uri list before adding to ensure uniqueness, however I see stack overflow uses a number plus a uri. This I assume allows titles to be duplicated?
View 3 Replies
Jan 6, 2010
My C# site allows users to submit HTML to be displayed on the site. I would like to limit the tags and attributes allowed for the HTML, but am unable to figure out how to do this in .net.
I've tried using Html Agility Pack, but I don't see how to modify the HTML, I can see how to go through the HTML and find certain data, but actually generating an output file is baffling me.
Does anyone have a good example for cleaning up HTML in .net? The agility pack might be the answer, but the documentation is lacking.
View 6 Replies
May 9, 2010
I am wondering having clear web.config file could be good but you know some shared web hosting companies don't allow us to touch things like machine.config and etc.
So If a lot of things have been moved onto machine.config, then will we be allowed to change things like we used to through web.config file.
View 1 Replies
Aug 11, 2010
There is an image for the surface, and a text is written on the image for 184 rows of date..
Thus, it is expected to see 184 different text written image files are generated with all the same background images. (The code is declared below...)
The problem is that the first text is written for all 184 different data.. I think I have to remove something in the loop. But what is that ??
[Code]....
View 1 Replies
May 21, 2010
Is there a better way to write the code below? I have quite a few blocks that are similar, and this is making the code in the Viewpage very messy to work with. The data value with the associated label only needs to be output when certain conditions are met, which is almost always if the value is not null. The options I can think is to use a response.write to atleast minimize the usage of the ASP script tags, or to format the webpage is such a way that the label displays with an appropriate n/a type value.
<% if (myData.Balance != null)
{ %>
Balance: <%= String.Format("{0:C}", (myData.Balance))%>
<% } %>
View 2 Replies
Dec 9, 2010
I once asked for a way to let a linkbutton pass more than one value in the commandArgument and then I reached the approach where I pass a string of multiple values separated by any character and split it into it's original parts...that didn't work out I don't know what was wrong with the splitting!
Now I tried the only solution I got, which is created a user control of the LinkButton and add properties to accept any values nedeed!...could you please tell me what's wrong with my 2 approaches and which is better ?
The first question can be found here : link text
and this is the code for the user control approach >>
MultivaluedLinkButton.ascx :
<asp:LinkButton ID="LnkBtnSort" runat="server" Text="Sort" OnClick="LnkBtnSort_Clicked"/>
MultivaluedLinkButton.ascx.cs :
public partial class MultivaluedLinkButton : System.Web.UI.UserControl
{
public event EventHandler Click;
private int _sortingType;
private string _sortingFactor;
private string _text;
public int SortingType
{
set { _sortingType = value; }
get { return _sortingType; }
}
public string SortingFactor
{
set { _sortingFactor = value; }
get { return _sortingFactor.ToString(); }
}
//public string Text
//{
// set { _text = value; }
// get { return _text.ToString(); }
//}
protected void LnkBtnSort_Clicked(object sender, EventArgs e)
{
if( Click != null )
{
this.Click(this, EventArgs.Empty);
}
}
}
Finally, Here's the implementation of my control inside an aspx page:
protected void MultivaluedLinkButton1_Clicked(object sender, EventArgs e)
{
MultivaluedLinkButton ctrl = (MultivaluedLinkButton)sender;
using (SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cm1 = new SqlCommand(commandString2, cn1))
{
cm1.Parameters.Add("@arrange_by_id", System.Data.SqlDbType.Int);
cm1.Parameters["@arrange_by_id"].Value = ctrl.SortingType;
cn1.Open();
using (SqlDataReader dr1 = cm1.ExecuteReader())
{
SortBy_rpt.DataSource = dr1;
SortBy_rpt.DataBind();
}
}
}
}
The item template of the repeater in the implementation page :
<ItemTemplate>
<uc1:MultivaluedLinkButton ID="MultivaluedLinkButton1" runat="server" OnClick="MultivaluedLinkButton1_Clicked" SortingType='<%#Eval("arrange_by_id")%>' />
</ItemTemplate>
View 1 Replies