How to get the Url for urlAction helper class? - c#

I am using Asp.net MVC.
I want to send a url of my application in a mail.
So That instead of sending url like "/Home/Index", I'd like to use url.action() method, as I've modified my url for IIS 7.0 classic mode (e.g. "/home.aspx/Index").
So How can I do that in C#?
We may need to use constructor, But don't have clear idea...

http://weblogs.asp.net/srkirkland/archive/2009/09/17/a-urlhelper-extension-for-creating-absolute-action-paths-in-asp-net-mvc.aspx
or a better explanation on http://msdn.microsoft.com/en-us/library/cc668201.aspx

Url.Action("MyAction", "MyController")
The code above should produce: /MyController/MyAction
Or in your case, using classic mode: /MyController.aspx/MyAction

Related

Custom URL making- URL rewrite

My URL is "http://properties.Poject.net/Public.aspx?account=ACCOUNT&id=HL101"
and my desired URL is http://properties.Poject.net/ACCOUNT/HL101
Please help me to achieve this. ALso i don't have URLWrite option in my IIS 6 and my project is under .net 3.5. Please help me config in Web.config
Thanks.
Manu
Use the concept called Url Routing in asp.net
refer article
http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/url-routing
http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
use the following two links, it briefly describe how to apply url Routing,by the way URL routing is more advance concept then URL rewriting so use that.....
https://web.archive.org/web/20211020111718/https://www.4guysfromrolla.com/articles/012710-1.aspx
http://msdn.microsoft.com/en-us/magazine/dd347546.aspx

i want to redirect the my all webpage url

is any possible way to rewrite my all webpage url. For example i was create a webpage name index.aspx and Event_view.aspx. It show in the address bar something like this..
http://localhost:65232/HRM/user/index.aspx
http://localhost:65232/HRM/user/Event_view.aspx
I want to convert the above url to something like this http://localhost:65232/HRM/user/sdf-3434sd34-343243-#45_343/Event_view
please help me to redirect the webpage url..
You can use URLRewrite module. The below link will give you a good walkthrough
http://www.asp.net/web-forms/videos/how-do-i/how-do-i-implement-url-rewriting
http://dotnetguts.blogspot.in/2008/07/url-rewriting-with-urlrewriternet.html
if you are using IIS 7 you can use "rewrite http module", or write your own httpmodule to rewrite the url.
if using iis 6 you can create an isapi.dll by c++ or python or write your own httpmodule to rewrite the url and host it in your web.config
take a look at here

Removing Localhost url in asp mvc

Just having a problem trying to properly display an image from an external site but mvc constraints links and automatically adds the localhost: url at the start of everything even with custom routing this cannot be avoided
eg I require: www.google.com/finance/chart?q=NYSE:V&tlf=12
but i am getting: http://localhost:3022/www.google.com/finance/chart?q=NYSE:V&tlf=12
any help would be much appreciated
Your problem is not MVC; it is the formation of your <a> tags. You are doing it like this:
blah...
You should be doing it like this:
blah...
Without including the protocol at the beginning, the browser assumes your link is relative to the current site. It has nothing whatsoever to do with MVC.
If you require a link on a separate domain, you need to add http://
So :
http://www.google.com/finance/chart?q=NYSE:V&tlf=12
Should work!
Why? Without the http, the link is considered relative and the browser uses the relative domain -> localhost!

mapRoute to a Web Form using ASP.NET 4

I have a Url like this
http://localhost:4737/Site/listing/NH/Plaistow/2831516
and I want it to reroute to
http://localhost:4737/Site/listing.aspx
I was reading how to do this for Web Forms here
https://web.archive.org/web/20211020111718/https://www.4guysfromrolla.com/articles/012710-1.aspx
Here's what my route looks like.
routes.MapRoute(
"FriendlyUrl",
"Site/listing/{state}/{town}/{mlsnumber}",
"~/Site/listing.aspx");
In my listing page I plan on accessing the following variables
Page.RouteData.Values["state"]
Page.RouteData.Values["town"]
Page.RouteData.Values["mlsnumber"]
But when I navigate to http://localhost:4737/Site/listing/NH/Plaistow/2831516,
I just get a HTTP 404 error.
I know how to get this working with MVC, but this is a fairly large application, all written with web forms, so rewriting isn't feasible.
Any ideas on how to troubleshoot this would be helpful.
Thanks !
Here is the working code. Thank you to mrchief for helping me resolve this.
routes.MapPageRoute(
"FriendlyUrl",
"listing/{state}/{town}/{mlsnumber}",
"~/listing.aspx");
Yore doing it the other way. If you're using WebForms, you need to implement UrlRoutingModule as shown here: https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx
The Routing Rules were designed for use in ASP.Net MVC applications where you redirect a Url to its appropriate Controller (Page in WebForms) with action params (query params in WebFroms parlance).

url rewrite for aspx page

I have a page, called foo.aspx and i d like to rewrite the url as bar.something
How to do this? How does url rewrite happens in asp.net
Should i create a generic handler?
or should i get some url rewrite modules and add to app?
This is done by configuring IIS, and will require IIS7, look here for configuration help:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
Remember, you also have the new Routing option with ASP.NET 4.0:
https://stackoverflow.com/questions/90112/iis-url-rewriting-vs-url-routing
You should also check this SO response:
IIS URL Rewriting vs URL Routing
Some basic info on the differences between URL Re-Writing and Routing:
http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/

Categories