The key point is to understand what happens rather than really to read code (after all it could work as it wors locally). Don't you have an exception shown in one of those labels ? If using TextBoxSONUC.Text = "[" & yaz & "]" and see [] it would show that
the assignement is done as expected but that the content of the file is just empty for some reason.
Perhaps not directly related but changing permissions on the file system is not usual. It could be that you have an exception because the account under which the web app runs is just not allowed to do that.
You are 100% sure you don't have an exception? My 2nd guess is that the file is left empty. The (aa < bb
And bb < cc And cc < dd And dd < ee And ee < ff) condition might be false (is this the real code, or show a message in Label_0.Text as well so that you know something has been written to the file). Could it be that you changed
the code between your local test and your deployment test.
Hi, PatriceSc
Thank you for your response,
Only 1 message from Label_2 is generating when working locally, which is "File Succesfully written! ". No information from other labels.
While running on hosting server if clicked sonuclarıhazırla button on result_2.aspx page then the page closes and error page opens which is ErrorPages/Ooops.aspx?aspxerrorpath=Result_2aspx.
one time while working on code s I received 'D:\www\Customer\lotterymatic.com\http\App_Data\Result.txt'. That means Result.txt file is only accessible on local server but not on hosting server. This is the problem
"yaz" is a portion of filestream I think. it could be any word, for example "write"
aa,bb,cc,etc are varibles and calculated in Class1.vb page.
Ok so you do have an exception server side which triggers your "oops" custom error page. Do you have access to the server event viewer to get details for this exception? Another option could be to extend the scope of your try/catch blocks.
My guess is that the account under which your app runs is not allowed to alter file permissions (but check first which exact exception you have). If confirmed and as this design is really unusual, rather than trying to make this work it might be better to
close this thread and open some new thread about to best achieve your unknown goal (or could it be an attempt to fix a previous problem you had ?).
According to your description and code, I guess code has no problem, because you could run success in localhost.
you say when run it in remote server, TextBoxSonuc don't show text, I notice the code, text is read from the txt file.
so I suspect when you run it in the server, the path of txt file have been change, I suggest you could replace variable
yaz with fixed text.
if it shows, turn out that it is txt file path issue.
Best Regards,
Eric Du
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Hi, PatriceSc
I looked the event viewer(local) window and try to understand the application section.
My knowledge is not enough yet to get some points which helps my issue.
Could you give me some detail to extend the scope of my try/catch blocks.
in the mean time I changed the code no 6 ommiting yaz variable.The new code no 6 is as follows:
'6-Reading and writing
Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
'Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = sr.ReadToEnd()
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
I compiled the application and load Bin files to hosting server. Received the same error page /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx
I did not understand why to close this thread and open some new thread
Best Regards
arkanturk
Hi Eric Du
I did not understand to replace variable yaz with fixed text. İnsted I changed the code no 6 ommiting yaz variable.The new code no 6 is as follows:
'6-Reading and writing
Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
'Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = sr.ReadToEnd()
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
I compiled the application and load Bin files to hosting server. Received the same error page /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx
Best Regards
arkanturk
I meant move the Try at step 6 to step 5 so that changing file permission is included as well in a try block. This way you should see an exception message if this is the point that is causing the issue which is likely (else you should find an exception message
in the Windows event viewer).
Or just remove that? Is this really needed ? Usually I would expect App_Data to be configured once for all in read/write mode for the account that runs your web application. I'm pretty sure the point is that your web app is not allowed to change permission
on this file (and for now I don't see why you are doing that).
Firstly I removed step 5 complitely and run on local server. TextBoxSONUC displaid the content of result.txt and Label_2 displaid "File Succesfully written! " message
Then I compiled the application and load Bin files to hosting server. Run the App and the same error page /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx is opened.
Secondly I put step5 and step6 alltogether in Try and Catch blog as this:
'5- security Rule "everyone" again
try
Dim sec As System.Security.AccessControl.FileSecurity = File.GetAccessControl(Server.MapPath("~/App_Data/Result.txt"))
'6-Reading and writing
' Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
'Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = sr.ReadToEnd()
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
after running on local server. TextBoxSONUC displaid the content of result.txt and Label_2 displaid "File Succesfully written! " message
Then I compiled the application again and load Bin files to hosting server. Running the App. Result_2aspx page opened as usual.
There are two buttons on this page. when clicked Button_SomuclariHazirla /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx is opened.
I closed the page and clicked second button on page Result_2.aspx. which is Button_SiparişleriListele.
Label_2 displaid "D:\www\customer\lotterymatic.com\http\App_Data\Result.txt " message.
This is the path of Result.txt Text File on hosting server. I dont know how to reach to thix text file
Just deal with the first error. As it happens in Button_SomuclariHazirla have you done the same work to show a possible exception. I believe it fails when you try to set a permission for this file. Do you deploy App_Data content?
For now I would do a test page that just create a file in App_Data and then delete it. I believe that maybe you had a file access error to App_Data and though to solve your issue by adding this file permission code. Instead you should be able to configure
your hosting service to allow that.
Please do not consider my last test (combining step6 and step7 codes keeping the other steps as it is.), because some other unwanted codes interfere it.
example for GoDaddy awakined me.
I will contact my hosting company to ask if there is any file access permission problem to App_Data folder. Data base files of the web site are residing and running in the same folder
I deleted Button_SiparişleriListele and put the related codes
in the last part of
Protected Sub Button_SomuclariHazirla_Click(sender As Object, e As System.EventArgs) Handles Button_SomuclariHazirla.Click
The New sequence is as follows:
‘in Result_2.aspx.vb page
Protected Sub Button_SomuclariHazirla_Click(sender As Object, e As System.EventArgs) Handles Button_SomuclariHazirla.Click
'1- Delete the file
'2-Create the file.
'3- Access Rule
‘in Class1.vb page
'4_ Writing the File
'5- security Rule "everyone" again
'6-Reading and writing
End Sub
The Hosting company confirmed that if Access Rule works fine there will be no problem accesing to result .txt file
Now I am concerned that how can one Result.txt file serves to different users
Each user should work with his or her unique Result.txt file. while creating the file, is it possible to add some words or numbers to the name result. Can you show me a path???
Member
4 Points
14 Posts
The Code performing well in local machine but not on remote server. The users can not see the con...
Mar 08, 2017 03:39 PM|arkanturk|LINK
‘Here are the code:
‘in Page Result_2.aspx.vb
Protected Sub Button_SomuclariHazirla_Click(sender As Object, e As System.EventArgs) Handles Button_SomuclariHazirla.Click
'1- Delete the file
Dim Path As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Try
'Delete the file if it exists.
If File.Exists(Path) Then
File.Delete(Path)
End If
Catch ex As Exception
Label_1.Text = ex.Message
Finally
End Try
'2-Create the file.
Using fs As FileStream = File.Create(path)
Dim info As Byte() = New UTF8Encoding(True).GetBytes("")
fs.Write(info, 0, info.Length)
fs.Close()
End Using
'3- Access Rule
Dim sec As System.Security.AccessControl.FileSecurity = File.GetAccessControl(Server.MapPath("~/App_Data/Result.txt"))
sec.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow))
File.SetAccessControl(Server.MapPath("~/App_Data/Result.txt"), sec)
‘in Class1.vb page
'4_ Writing the File
Public Sub Listele_Urun_1_Siparisleri_RANDOMLU()
Dim YOL As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(YOL, FileMode.Append, FileAccess.Write)
Dim sw_1 As New StreamWriter(fs)
Try
Dim aa, bb, cc, dd, ee, ff As Byte
Dim Random_Say_Urun_1 As Integer
Counter_v = 0
Random_Say_Urun_1 = 0
If (aa < bb And bb < cc And cc < dd And dd < ee And ee < ff) Then
Counter_v = Counter_v + 1
For Each R_1 In ArrayList_Urun_1
If R_1 = Counter_v Then
Random_Say_Urun_1 = Random_Say_Urun_1 + 1
sw_1.WriteLine(" ÜRÜN 1- " & Random_Say_Urun_1 & "; ( " & aa & " - " & bb & " - " & cc & " - " & dd & " - " & ee & " - " & ff & ")", True)
Exit For
Else
End If
Next
Else
End If
sw_1.Close()
fs.Close()
Catch ex As Exception
Label_0.Text = ex.Message
Finally
End Try
End Sub
‘in Result_2.aspx.vb page
Protected Sub Button_SiparişleriListele_Click(sender As Object, e As System.EventArgs) Handles Button_SiparişleriListele.Click
'5- security Rule "everyone" again
Dim sec As System.Security.AccessControl.FileSecurity = File.GetAccessControl(Server.MapPath("~/App_Data/Result.txt"))
sec.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow))
File.SetAccessControl(Server.MapPath("~/App_Data/Result.txt"), sec)
'6-Reading and writing
Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = yaz
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
‘7_Deleting again
Dim path As String = Server.MapPath("~/App_Data/Result.txt")
Try
If File.Exists(path) Then
File.Delete(path)
End If
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
End Sub
All-Star
48730 Points
18189 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 08, 2017 04:19 PM|PatriceSc|LINK
Hi,
The key point is to understand what happens rather than really to read code (after all it could work as it wors locally). Don't you have an exception shown in one of those labels ? If using TextBoxSONUC.Text = "[" & yaz & "]" and see [] it would show that the assignement is done as expected but that the content of the file is just empty for some reason.
Perhaps not directly related but changing permissions on the file system is not usual. It could be that you have an exception because the account under which the web app runs is just not allowed to do that.
You are 100% sure you don't have an exception? My 2nd guess is that the file is left empty. The (aa < bb And bb < cc And cc < dd And dd < ee And ee < ff) condition might be false (is this the real code, or show a message in Label_0.Text as well so that you know something has been written to the file). Could it be that you changed the code between your local test and your deployment test.
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 08, 2017 07:05 PM|arkanturk|LINK
Hi, PatriceSc
Thank you for your response,
Only 1 message from Label_2 is generating when working locally, which is "File Succesfully written! ". No information from other labels.
While running on hosting server if clicked sonuclarıhazırla button on result_2.aspx page then the page closes and error page opens which is ErrorPages/Ooops.aspx?aspxerrorpath=Result_2aspx.
one time while working on code s I received 'D:\www\Customer\lotterymatic.com\http\App_Data\Result.txt'. That means Result.txt file is only accessible on local server but not on hosting server. This is the problem
"yaz" is a portion of filestream I think. it could be any word, for example "write"
aa,bb,cc,etc are varibles and calculated in Class1.vb page.
arkanturk
All-Star
48730 Points
18189 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 08, 2017 08:03 PM|PatriceSc|LINK
Ok so you do have an exception server side which triggers your "oops" custom error page. Do you have access to the server event viewer to get details for this exception? Another option could be to extend the scope of your try/catch blocks.
My guess is that the account under which your app runs is not allowed to alter file permissions (but check first which exact exception you have). If confirmed and as this design is really unusual, rather than trying to make this work it might be better to close this thread and open some new thread about to best achieve your unknown goal (or could it be an attempt to fix a previous problem you had ?).
Contributor
6730 Points
2715 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 09, 2017 03:03 AM|Eric Du|LINK
Hi arkanturk,
According to your description and code, I guess code has no problem, because you could run success in localhost.
you say when run it in remote server, TextBoxSonuc don't show text, I notice the code, text is read from the txt file.
so I suspect when you run it in the server, the path of txt file have been change, I suggest you could replace variable yaz with fixed text.
if it shows, turn out that it is txt file path issue.
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 09, 2017 08:11 AM|arkanturk|LINK
Hi, PatriceSc
I looked the event viewer(local) window and try to understand the application section.
My knowledge is not enough yet to get some points which helps my issue.
Could you give me some detail to extend the scope of my try/catch blocks.
in the mean time I changed the code no 6 ommiting yaz variable.The new code no 6 is as follows:
'6-Reading and writing
Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
'Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = sr.ReadToEnd()
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
I compiled the application and load Bin files to hosting server. Received the same error page /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx
I did not understand why to close this thread and open some new thread
Best Regards
arkanturk
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 09, 2017 08:13 AM|arkanturk|LINK
Hi Eric Du
I did not understand to replace variable yaz with fixed text. İnsted I changed the code no 6 ommiting yaz variable.The new code no 6 is as follows:
'6-Reading and writing
Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
'Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = sr.ReadToEnd()
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
I compiled the application and load Bin files to hosting server. Received the same error page /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx
Best Regards
arkanturk
All-Star
48730 Points
18189 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 09, 2017 09:00 AM|PatriceSc|LINK
I meant move the Try at step 6 to step 5 so that changing file permission is included as well in a try block. This way you should see an exception message if this is the point that is causing the issue which is likely (else you should find an exception message in the Windows event viewer).
Or just remove that? Is this really needed ? Usually I would expect App_Data to be configured once for all in read/write mode for the account that runs your web application. I'm pretty sure the point is that your web app is not allowed to change permission on this file (and for now I don't see why you are doing that).
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 09, 2017 01:09 PM|arkanturk|LINK
Hi, PatriceSc
Firstly I removed step 5 complitely and run on local server. TextBoxSONUC displaid the content of result.txt and Label_2 displaid "File Succesfully written! " message
Then I compiled the application and load Bin files to hosting server. Run the App and the same error page /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx is opened.
Secondly I put step5 and step6 alltogether in Try and Catch blog as this:
'5- security Rule "everyone" again
try
Dim sec As System.Security.AccessControl.FileSecurity = File.GetAccessControl(Server.MapPath("~/App_Data/Result.txt"))
sec.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow))
File.SetAccessControl(Server.MapPath("~/App_Data/Result.txt"), sec)
'6-Reading and writing
' Try
Dim FilePath As String = HttpContext.Current.Server.MapPath("~/App_Data/Result.txt")
Dim fs As New FileStream(FilePath, FileMode.Open)
Dim sr As New StreamReader(fs)
'Dim yaz As String = sr.ReadToEnd()
TextBoxSONUC.Text = sr.ReadToEnd()
Label_2.Text = "File Succesfully written! "
sr.Close()
fs.Close()
Catch ex As Exception
Label_2.Text = ex.Message
Finally
End Try
after running on local server. TextBoxSONUC displaid the content of result.txt and Label_2 displaid "File Succesfully written! " message
Then I compiled the application again and load Bin files to hosting server. Running the App. Result_2aspx page opened as usual.
There are two buttons on this page. when clicked Button_SomuclariHazirla /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx is opened.
I closed the page and clicked second button on page Result_2.aspx. which is Button_SiparişleriListele.
Label_2 displaid "D:\www\customer\lotterymatic.com\http\App_Data\Result.txt " message.
This is the path of Result.txt Text File on hosting server. I dont know how to reach to thix text file
Best regards
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 10, 2017 08:20 AM|arkanturk|LINK
Hi, PatriceSc
I made another test combining step6 and step7 codes keeping the other steps as it is. and get some more information on the problem.
New Code s
'6 and 7 Reading and writing and deleting
Dim fp As StreamWriter
Try
fp = File.CreateText(Server.MapPath("~/App_Data/Result.txt"))
fp.WriteLine(TextBoxSONUC.Text)
Label_2.Text = "File Succesfully erased!"
fp.Close()
Catch err As Exception
Label_2.Text = "File Erase failed. Reason is as follows " & err.ToString()
Finally
End Try
I run on local server. No problem, TextBoxSONUC displaid the content of result.txt and Label_2 displaid "File Succesfully erased! " message
Then I compiled the application and load Bin files to hosting server. Running the App.
Result_2aspx page opened as usual.
After clicking Button_SomuclariHazirla /ErrorPages/Oops.aspx?aspxerrorpath=/Result_2.aspx is opened.
I closed the page and clicked second button on page Result_2.aspx. which is Button_SiparişleriListele.
and received the following:
File Erase failed. Reason is as follows System.UnauthorizedAccessException: Access to the path 'D:\www\customer\lotterymatic.com\http\App_Data\Result.txt' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at 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, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append) at System.IO.File.CreateText(String path) at Result_2.Button_SiparişleriListele_Click(Object sender, EventArgs e)
Could you please translate this message .
All-Star
48730 Points
18189 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 10, 2017 09:08 AM|PatriceSc|LINK
Just deal with the first error. As it happens in Button_SomuclariHazirla have you done the same work to show a possible exception. I believe it fails when you try to set a permission for this file. Do you deploy App_Data content?
For now I would do a test page that just create a file in App_Data and then delete it. I believe that maybe you had a file access error to App_Data and though to solve your issue by adding this file permission code. Instead you should be able to configure your hosting service to allow that.
Edit: for example for GoDaddy: https://therelentlessfrontend.com/2010/03/14/setting-write-permission-to-app_data-for-a-godaddy-hosted-site/
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 10, 2017 12:21 PM|arkanturk|LINK
Hi, PatriceSc
Please do not consider my last test (combining step6 and step7 codes keeping the other steps as it is.), because some other unwanted codes interfere it.
example for GoDaddy awakined me.
I will contact my hosting company to ask if there is any file access permission problem to App_Data folder. Data base files of the web site are residing and running in the same folder
thank you for your help
arkanturk
Member
4 Points
14 Posts
Re: The Code performing well in local machine but not on remote server. The users can not see the...
Mar 13, 2017 02:15 PM|arkanturk|LINK
Hi, PatriceSc
Thank you very much for your valuable assistance
Problem is solved.
I deleted Button_SiparişleriListele and put the related codes
in the last part of
Protected Sub Button_SomuclariHazirla_Click(sender As Object, e As System.EventArgs) Handles Button_SomuclariHazirla.Click
The New sequence is as follows:
‘in Result_2.aspx.vb page
Protected Sub Button_SomuclariHazirla_Click(sender As Object, e As System.EventArgs) Handles Button_SomuclariHazirla.Click
'1- Delete the file
'2-Create the file.
'3- Access Rule
‘in Class1.vb page
'4_ Writing the File
'5- security Rule "everyone" again
'6-Reading and writing
End Sub
The Hosting company confirmed that if Access Rule works fine there will be no problem accesing to result .txt file
Now I am concerned that how can one Result.txt file serves to different users
Each user should work with his or her unique Result.txt file. while creating the file, is it possible to add some words or numbers to the name result. Can you show me a path???
Best Regards