asp HyperLink for IIS directory browsing - c#

I have been trying this and it does not seem like it wants to work out for me today. I want to have an hyperlink to a log folder which in IIS is enabled with directory browsing but asp.net does not like the link so it does not even send it to the client.
<asp:HyperLink ID="HyperLink8" NavigateUrl="~/logs/" runat="server"></asp:HyperLink>
The reason why I am doing this is that the log link is in the footer of the master page. I cannot control the virtual directory name so I cannot effectively use the anchor tag. Any one encountered this before ?
Thanks,

It probably is sending the link to the client, but without setting the Text value it will be invisible.

Related

moved web form does not load

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

Not showing the images in live server which is showing in my local host

I am working on the Mailbox Module in VS2010 with C#
I have made a control with ascx page and in that page I have created Three different gridviews for Inbox,SentItems and Deleted Items.
In all the three gridviews I have added two columns for the Images for Reply and Forward messages which is shown where the user reply or forward the message.
The functionality works perfectly in my localhost.
But today i have deployed it on live server.
Where I found that I does not showing the images.
When I inspected elements through firebug I found in the HTML source code that it shows me that the "Failed To Load The Given URL" while for other images it shows the images.
Can Anyone tell me why is it happening and help me..?
Check if the url is pointing to the correct physical path on live sever.
Refer this - ASP.NET Web Project Paths
ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.
The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.
<asp:image runat="server" id="Image1"
ImageUrl="~/Images/SampleImage.jpg" />
You can use the ~ operator in any path-related property in server controls. The ~ operator is recognized only for server controls and in server code. You cannot use the ~ operator for client elements.
I found solution of this error.
Basically in Help desk set permision red and write where u hosting website. then solve thi solution.
2nd thing: u check folder image folder path where u save image in Help desk

Response.Redirect with a subdirectory in url

I have a little problem with my Redirect in ASP.NET (C#)
I just got a domain which looks like this: http://www.example.com/subdirectory
So when I open my asp.net start page, the url looks like this: http://www.example.com/subdirectory/Startpage/Startpage.aspx
That's my Redirect in code behind:
Response.Redirect("~/UserSite/UserSite.aspx")
The problem now is, when I click on that button, I get redirected to
http://www.example.com/UserSite/UserSite.aspx
instead of
http://www.example.com/subdirectory/UserSite/UserSite.aspx
How can I get my web page to notice the subdirectory in the url?
Would be nice if someone could help me.
Thanks.
This may be because your website under the sub-drecitory hasn't been setup as it's own application within IIS7.
You can do this by:
Open IIS Manager
Open up the website and right click on the sub directory
Click on "Convert to Application"
You can then change the Application Pool if you wish to have a dedicated one or otherwise just click OK.
Response.Redirect("~/UserSite/UserSite.aspx") should then understand that /subdirectory/ is the default website directory

Display FileUpload full path after page refresh

I have a FileUpload control in my ASP page. Once I choose a file from disk it will display the full path C:\users\star\one.jpg on its textbox.
<asp:FileUpload ID="filUpload1" runat="server" />
Then I have done some validation clicking button. As result of that button click event it will occur page refresh. And it will clear that file path on control.
How Can I display FileUpload full path after page refresh?
I have tried ViewState ,However it dosn't allow me to store full path itself. Please help me.
This is not possible.
Asp.net uses html forms to send its data. Due to browser security constraints and user privacy issues, the full path is not sent to the server.
However on the next postback that occurs, the full file does get uploaded to the server.
Using the FileUpload control, the contents of the file are only available on the first postback after the user selected the file.
What you should do is save this file at that time, and make a note of it in the ViewState(Where you saved the file on the server).
When when final submit occurs, you can use the file that is already uploaded on your server.
you have interessant article on this link
http://www.ironspeed.com/articles/Maintain%20File%20Upload%20Control/Article.aspx

ASP.NET/SharePoint master page issue

I am using SharePoint Server 2007 + C# + .Net 3.5 + VSTS 2008 + ASP.Net. And I am using collaboration portal template.
I am developing a custom aspx page and put it in _layout folder of a site and I want to apply default.master of the SharePoint site to this aspx page. Any samples about how to achieve this goal?
You can put code in the PreInit event to make your custom page use the current site's masterpage.
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPWeb myWeb = SPControl.GetContextSite(Context).OpenWeb();
string strUrl = myWeb.ServerRelativeUrl + "/_catalogs/masterpage/my.master";
this.MasterPageFile = strUrl;
}
Or replace my.master with default.master in order to use the default master page. Or check spweb's MasterUrl property and use that instead.
Either way it should get you going in the right direction.
If you use SharePoint Designer then you can right-click on your page and then select a Master page to apply.
The best way to do this is by use of an HttpModule. This enables the use of your custom master page for all application pages (i.e. pages in the LAYOUTS folder). It can be deployed using a feature and can be activated per web application (seeing as the httpmodule needs to be registered in the web.config it is web app scoped.)
By making it web app scoped, your end users will have a uniform user experience, instead of that single page looking like the front end of the site while all the other (Out of the box) application pages are still using the default sharepoint application.master.
For a code example and a more in depth explanation, look here.
P.S. You are getting errors using the code above because of missing content placeholders. You need to create a copy of your custom master page. Although styling can be the same, application pages use more/other ContentPlaceHolders than a front end master page.
Just copy your custom master page, rename it from CustomMaster.master to, say, CustomMasterEdit.master and use that for application page styling, SharePoint will throw an error telling you which placeholders are missing, keep adding the needed placeholders till the page works (there are 2 or 3 extra placeholders needed i believe).
P.P.S. To make sharepoint display errors that make sense, go the web.config and look for the <SharePoint> tag and change the callstack attribute from false to true. Then, look for the customErrors tag and set the mode attribute to "off". To completely enable debugging, you can also enable ASP.NET tracing. Of course you should NOT do this in your production environment....
More info on modifying the web.config to make sharepoint display real error message can be found here.
and

Categories

Resources