Recover URLs for an ASP.NET Page in IIS

Well, I had a huge question giving this correct name, my excuses for this.

Anyway, I started looking slowly at Web and ASP.NET again, I am a C # developer, but I have mainly worked with Windows applications for the last 5 years or so. Not that I didn’t touch the Internet, such as at that time, but it’s like web services (Restfull, as well as ugly SOAP services). I also worked with more raw web requests.

But I have not worked with IIS or ASP.NET all this time.

What I would like to do is a hos webpage that uses a URL style that I could better describe using "like rest", hence the header "Restfull urls". Since I think most people think of such a URL in terms of:

http://example.com/item/ http://example.com/item/23/ 

etc. Not that they looked like this, but I would like to use such a URL instead

 http://example.com/item?id=23 

I know that the subtext does this, but I was not lucky to find it in the code base.

Now, as far as I can tell, I could just implement some IHttpHandler, but at least for the examples I saw, they write the source code of the page into code, and I still have master pages, etc. I want to use instead of taking over all this, I really just want to direct http://example.com/item/23/ to http://example.com/item and request an element with id 23 ...

I hope this makes sense at all>. <... And someone has some of the best examples on hand that I could find.

+4
source share
4 answers

So here are your options -

For the .net 3.5 sp1 platform with IIS7, you can use the asp.net routing function so that the MVC style URLs you mentioned should create a custom route handler that implements the IRouteHandler interface, as described here "How to use routing with web forms " and register the route rules in the Application_Start method in Global.asax. For your example, you can register a route like this

  routes.Add("ItemRoute", new Route ( "item/{itemId}", new CustomRouteHandler("~/item.aspx") )); 

and then you can access itemId on the routed item.aspx page by checking the request context element

  requestContext.HttpContext.Items["itemId"] 

For the .NET Framework 4 MVC you do not need to create a custom handler, you can directly use

  routes.MapPageRoute("ItemRoute", "item/{itemId}", "~/item.aspx"); 

you have the global.asax Application_Start method.

This link explains more about routing.

+2
source

You can achieve this by using the Routing link here on the MSDN blog. The .Net endpoint is the use of routes to create WCF web services that should get started.

+3
source

If you are looking at asp.net/IIS, another option is ASP.Net MVC . It is quite simple to create RESTful services.

Here is a tutorial:

http://www.codeproject.com/Articles/233572/Build-truly-RESTful-API-and-website-using-same-ASP

+3
source

A way to achieve this is to use URL rewriting.

If you plan to host your web application in Internet Information Services 7.x, you can use the IIS URL rewriter module:

Rewriting URLs simply maps a friendly URL to an unfriendly, generic, programming friendly way to check for GET parameters.

For instance:

 http://yourdomain.com/item/48 => http://yourdomain.com/Items.aspx?Id=48 
+1
source

Source: https://habr.com/ru/post/1392256/


All Articles