سلام دوستان :
من یه برنامه با وبکلاینت نوشتم اما برنامم تو هاست کار نمی کنه دلیلش چیه ؟
کد:
Dim a As Net.WebClient = New Net.WebClient
Page.Title = TextBox2.Text
a.DownloadFile(TextBox2.Text, Server.MapPath("/agary.rar"))
Label1.Text = "Done!"
این برنامم هست .
کد:
Server Error in '/Agary' Application.
Access to the path 'C:\AspSpiderRoot\agary.rar' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\AspSpiderRoot\agary.rar' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[UnauthorizedAccessException: Access to the path 'C:\AspSpiderRoot\agary.rar' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +9611170
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +1142
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) +84
System.Net.WebClient.DownloadFile(Uri address, String fileName) +160
[WebException: An exception occurred during a WebClient request.]
System.Net.WebClient.DownloadFile(Uri address, String fileName) +383
System.Net.WebClient.DownloadFile(String address, String fileName) +32
WebApplication2._Default.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Agary\My Documents\Visual Studio 10\Projects\WebApplication2\WebApplication2\Default.aspx.vb:7
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.21006; ASP.NET Version:4.0.21006.1
اینم ارروریه که سرور می ده . خود سرور اجازه ی استفاده نمی ده یا اشکالم تو به دست آوردن محل برنامست ؟
من از هاست
ای اس پی استفاده می کنم .
متشکرم
سلام خودم پاسخش رو پیدا کردم :
کد:
a.DownloadFile(TextBox2.Text, Server.MapPath("/agary.rar"))
به جای مورد بالا باید بنویسیم :
کد:
a.DownloadFile(TextBox2.Text, Server.MapPath("~/agary.rar"))
علامت ~ برای برنامه های سرور ساید هست و در به دست آوردن مکان سرور (پوشه ی جاری) کمک می کنه.
البته اگر در مورد کاربردش اشتباه نکرده باشم.