I used web.sitemap to generate the site map path for my asp.net application.
and I can generate two lays just like:
http://localhost:8080/test.aspx
but If i need to generate the MVC path like this:
http://localhost:8080/test.aspx/edit/2
and I need to know the "2" to get the site map.
Is there any method that I can use wild card
http://localhost:8080/test.aspx/edit/*
and then for this kind of path, system will auto generate the path at the page header ?
http://mvcsitemap.codeplex.com/
IMO it's not possible. The default provider of Sitemap is static. You've to write a dynamic sitemap provider to generate the sitemap nodes from the data source.
http://www.codeproject.com/KB/aspnet/dynamicsitemap.aspx
Related
I have images in my web app that are currently retrieved from another domain:
<img src="https://images.other.net/{folder}/{filename}"/>
I want to rewrite all image urls to a specific action in my own domain but using some parts of the path above. The new URL should look like:
<img src="https://images.mydomain.net/en/home/getimage?name={filename}&folder={folder}"/>
where folder and filename are dynamic values.
I want to see if I can do it without actually changing all paths 1 by 1.
Can I do it either by MVC Routing rules or by URL rewrite rules in the web.config file?
Below is the list of several options to do that.
This list also contains the benefits/problems you will face using these methods:
Changing all paths:
You can change all the paths at once by using the find and replace option if the base URL of all the paths is the same.
The shortcut key for Find and Replace option is Ctrl + Shift + R .
If you will keep the base URL in multiple files/places in the code, it will create a problem for you if the URL will change in the future, you have to replace them again.
Put the base URL in a web.config key (Recommended)
Better approach is to create a key in the web.config file and put the base URL there so that even if it changes in the future you just have to change the URL once in the web.config file.
Using IIS URL Rewrite
You can get help from this article to create some URL rewrite rules.
For rewrite rule with dynamic values see this article.
I want to generate pages with asp.net. I have one page with the content I will show. I know that you can use a query string like this:
www.mysite.com/users.aspx?name=pol
With the code for read and place a query string, I have no problems and works very good.
But for the users it's more friendly to use this:
www.mysite.com/users/pol
How can you do this? I use ASP.NET, the background language is C#.
You can achieve this using URL Routing.
ASP.Net web forms applications doesn't support URL routing by default, but you can easily implement it by registering routes at the start of your application (in Global.asax file) as shown here -
http://weblogs.asp.net/scottgu/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series
When I go to get my images from my database in ASP.net and it loads in to the boundfield all I see is
this
~\Images\Husqvarna-HU700L.jpg
or
~\Images\Husqvarna-95600L.jpg
instead of the image because it's not in the root.
My site is not going to be in the root directory and I need to figure out how to resolve the url to an absolute. Would it be a link or some C# method?
I have a subdomain that is http://trade.businessbazaar.in . I am dynamically creating urls from database something in this manner http://trade.businessbazaar.in/mycompany. To display details, I have an index.aspx file there,thinking that on every request the index.aspx page will load and display data accodingly. Also, There is a masterpage on the index.aspx page from where i am capturing the text mycompany and query it in database to fetch result. But nothing seems to work.
A genuine link is http://trade.businessbazaar.in/Symparlife. But its unable to load index.aspx. I need a clean approach without any third party dll or rewriters. Directly to push some lines in config and start working. That is url will be the same but index page will get loaded...
In short, i want to say
I need the StackOverflow type clean url mechanism to fetch pages
Thanks in Advance
You can handle the Begin_Request event in Global.asax and add custom code to redirect to index.aspx and convert the parts of the URL into query string arguments. You should use Server.Transfer to keep the URL in the browser.
I'd recommend upgrading to 4.0 and using the Routing enine though. You should check if the standard routing is available as a download for ASP.NET 3.5. I am sure your code will get messy very soon. Been there, done that.
As #Mike Miller mentions in the comments the Routing engine ships with ASP.NET 3.5. You can check the documentation here - http://msdn.microsoft.com/en-us/library/system.web.routing(v=vs.90).aspx
Here is a tutorial on how to use it with Web Forms - 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
For your case the code would be something like:
routes.MapPageRoute("company-index", "/{company}", "~/index.aspx")
And in index.aspx you can access the route value for company like this:
string company = (string)Page.RouteData.Values["company"];
Keep in mind that you'd better add something in the URL before your actual argument (the company name). If you don't you will have problems later on when because you may want to add a URL like "/Login" but then you will have to validate that users can't create a company named "Login". Not how Stack Overflow has "/questions/" before the actual question info in the URL.
I'm remaking a website, previous build on DotNetNuke. I need to keep the database, as old URLs working.
The issue: translate the old URL
eq.
http://localhost:8069/Noticias/tabid/78/language/pt-BR/nid/2267/Palestra-
discute-o-futuro-profissional-das-crianca.aspx
to the new mapping engine, that would be something like that:
eq.
http://localhost:8069/{controller}/{action}/{id}/{title}
where, in the example, 2267 is my id, and 78 is the module id that i have to 'translate' for a controller name. The action is view by default.
Any suggestions?
Simply make a base page handler for the requests you want to transfer, and then do a simple Response.Redirect to the appropriate URL on your new website then. All your pages inherit these changes, and you can provide a listing of URLs in a configuration file or database for the URLs to dynamically redirect.