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?
Related
I'm a newbie at asp.net and I have asp.net application with nested master pages. (.Net 3.5) I had a web form at root directory and I moved it a folder which I created under root. From this point I started to get "cannot use a leading .. to exit above the top directory" error while that web form loading. I digged on web and I tried prefixes "~", "/", "../" but I'm nowhere. my code as follows.
<li>
Add New Staff
</li>
I tried to create one more web form under "Staff" directory, but this form also generates same error while loading. Appreciate for help.
if i am not wrong you are using double code in href. it should be like this depending on your folder structure.
Add New Staff
And
For anyone who has found this thread, addressing relative paths has always created arguments over what is correct or not.
Depending on where you use the path to be addressed, it will depend on how you address the path.
Generally :
. and ./ do the same thing, however you wouldn't use . with a file name. Otherwise you will have the browser requesting .filename.ext as a file from the server. The proper method would be ./filename.ext.
../ addresses the path up one level from the current folder. If you were in the path /cheese/crackers/yummy.html, and your link code asked for ../butter/spread.html in the document yummy.html, then you would be addressing the path /cheese/butter/spread.html, as far as the server was concerned.
/ will always address the root of the site.
In ASP.NET Web Form, we normally use HyperLink server control to create URL as mason said.
<asp:HyperLink runat="server" NavigateUrl="~/Staff/New_Staff.aspx" Text="Add New Staff"/>
If you do not want use it, you can manually prepend with <%= ResolveUrl("~/") %>.
Add New Staff
I have a nested master page, used for the admin part of a website. When I redirect to a login page from that master page, the redirect construct a weird url. "_hosting" is the actual folder in which the application folder "applicationname" is. So instead of having this :
www.sitename.com/admin/login.aspx
I get this :
www.sitename.com/_hosting/applicationname/admin/login.aspx
I try redirecting using "~/admin/login.aspx", remove the "~" and ".." but nothing works. When the application is run localy, it doesnt do that, It redirect corrrectly to:
http://localhost:63820/admin/login.aspx
I don't understand what is causing this. From what Ive read, it has something to do with the nested master page but didnt find anything that helped me solve this.
My last option would be to remove the unwanted part of the path and redirect that way, but I would like to solve this the right way.
thanks
Page always redirect on right path as you tell that your login page path is
www.sitename.com/_hosting/applicationname/admin/login.aspx
For the redirect login page you used this path but you can reduce it make a public class where
you take a constant variable and give here full path and use that constant variabe as redirect path
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.
,Hope i get this clear.
I have a asp.net website, as part of it i generate a bitmap and need to save it some were so i can display it later on.
for now my sites is locate here:
http://tools.myDomain.com/mySite/
I have created a directory with in my site:
http://tools.myDomain.com/mySite/img/
Now i am trying to save my bitmap to there like this:
bitmap.Save(#"http://tools.myDomain.com/mySite/img/bitmap.png");
I can get this to work, not from my computer locally and not when i do Publish to my site...
Any ideas how can i fix this problem?
Thank you
You need to save it on the server not on the web
bitmap.Save(HttpContext.Current.Server.MapPath("/img/bitmap.png"));
try
bitmap.Save(Server.MapPath("/mySite/img/bitmap.png"));
Or you can use an absolute path
bitmap.Save("c:\inetpub\wwwroot\mySite\img\bitmap.png");
Note that the path is just an example and should be your absolute path.
You need to add permissions for ASPNET user. It will work for sure.
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