LinkButton postbackurl Error in asp.net - asp.net

I want to send a Message by clicking on a LinkButton through yahoo messenger in Asp.net. Some times It works and sometimes I get this errors: Windows can not access the spesified device, path or file. You may not have appropriate permission to access this item and also Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 400 This is my code in VB, What is wrong with it?
Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
Dim idname As String = "YMID"
Dim message As String = "Hello, This is my YM message"
Dim sendim As String = String.Format("ymsgr:SendIM?{0}&m={1}", idname, message)
LinkButton2.PostBackUrl = (sendim)
End Sub

Related

How to represent the URL as it is in VB

I want to pass the exception Url as a string to a method that I have created , so that it shows the exception Url in the mail (that is sent).
I have done the following in my ApplicationError() event in my Global.asax
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Dim lastException As Exception = Server.GetLastError()
If (lastException Is Nothing) Then
Return
End If
Dim context As HttpContext = HttpContext.Current
Dim myMethodforMail As New myMethodforMail()
Dim exUrl As String = context.Request.Url.ToString()
Dim webServerName As String = Server.MachineName
myMethodforMail.HandleApplicationError(exUrl, webServerName)
Server.ClearError()
End Sub
But the url is printed as http://localhost:22035/examplepage.aspx?PageNumber!0331
instead of http://localhost:22035/examplepage.aspx?PageNumber=650331
could anyone kindly help me how to decode the ! in the Url and represent the Url as it is, please . ThankYou.

How to obtain client PC name which is accessing IIS web application?

This is a Vb.NET 4.0 framework web application which is deployed over iis.
I have a welcome label on my page which will display a different message based on the what the client PC name is. The problem is that I either obtain the webserver hostname/Ip address or I receive an error "No such host is known"
Here are the different methods that have been attempted with their varying error messages.
Thanks for looking
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
'No such host is known Error
'WelcomeMessage.Text = System.Net.Dns.GetHostEntry(Request.UserHostName).ToString
'WelcomeMessage.Text = (Dns.GetHostEntry(Request.ServerVariables("remote_addr")).HostName.ToString)
'WelcomeMessage.Text = System.Net.Dns.GetHostEntry(Request.ServerVariables("REMOTE_HOST")).HostName
'I receive the IPv6 ID
'WelcomeMessage.Text = Request.UserHostAddress
'I receive the web Server ID
'WelcomeMessage.Text = System.Net.Dns.GetHostName()\
Catch ex As Exception
WelcomeMessage.Text = ex.Message
End Try
End Sub

Make asp.net webpage respond to WebClient request

I have run into a problem in my asp.net and vb.net programming. I have made a website which connects to a database to authenticate users. I have made another page which my windows form application uses to authenticate users so the program does not have to connect directly to the MySql Database as this is insecure.
So far, the code for my asp.net page is:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Request.QueryString.Keys(0) = "key" And Request.QueryString.Keys(1) = "getapikeyv1" And Request.QueryString.Keys(2) = "authapienc2" Then
Dim key As String = Request.QueryString.Get("key")
If key = "dua9r3rqpK{WPDWp9r93af03r8yqrEPIF{A}W~DW)D08q3raewdawdug9q8wdyaw9wq" Then
returnLabel.Text = "XYeJay4XVh6amvf1kJ34Y6y6hR0sSokP9oJFsi0Mxl4QB0T86W0iac9o2nRfCmFmsONq6sPz+rdX+/NqFk3inHRGnwnqf0IsQXE/M/SvnvY="
Else
returnLabel.Text = "invk"
End If
Else
returnLabel.Text = "invalidrequest"
End If
End If
End Sub
The default value for 'returnLabel' is INVALIDREQUEST. My api keys defined above are working fine so are not needed to be considered here. However, when I use the following code to communicate with the webpage, it always returns with returnLabel's value as 'INVALIDREQUEST'. Even if I put the returnLabel.Text = "1233" at the beginning of the Me.Load sub, the page still returns INVALIDREQUEST when I communicate with it through my program!
I use this code to request:
Try
Dim APIRequest As New WebClient
APIRequest.QueryString.Add("key", r9j0wqfha0fh0wf0.DecryptString128Bit(APIKey5, dVadaihwdq93ra0w0))
APIRequest.QueryString.Add("getapikeyv1", "")
APIRequest.QueryString.Add("authapienc2", "")
Dim ako39rqwfa As String = APIRequest.DownloadString(EncryptionPageUrl)
MsgBox(ako39rqwfa)
Dim m As Match = Regex.Match(ako39rqwfa, "<span id=""returnLabel"">.*?</span>")
APIKey00 = m.Value.Replace("<span id=""returnLabel"">", "").Replace("</span>", "")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
As you can see, the WebClient I use is fine but the Me.Load sub in the webpage is not responding the request made by the program...
Is there any way I can make the webpage respond to the WebClient.DownloadString() function?
Thanks,
Rodit
(ps. c# or vb code would be appreciated)
Change your asp.net page to check the query string like this, not sure if you can assume they are in a certain order:
If Request.QueryString.Get("key") isnot nothing And
Request.QueryString.Get("getapikeyv1") isnot nothing And
Request.QueryString.Get("authapienc2") isnot nothing Then

gridview System.NullReferenceException: Object reference not set to an instance of an object.

i receive the error when my web app is published. when i run the app it works fine.
im using vs 2010
this is the line of code where it errors:
Dim money As String = footer.Cells(1).Text.Replace("£", String.Empty)
the aim is to have a look in the footer on the gridview and then remove the £ sign so that it no longer exist
i rowdatabound the information from an excel spreadsheet to the girdview
Protected Sub GridView5_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView5.RowDataBound
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "Total"
e.Row.Cells(1).Text = total.ToString("c")
End If
End Sub
can anyone help please
In this line here:
e.Row.Cells(1).Text = total.ToString("c")
Where is total initialised?
If it isn't initialised, then when you come to access it via Cells(1) here:
Dim money As String = footer.Cells(1).Text.Replace("£", String.Empty)
You will get the NullReferenceException

Report Viewer error: The request failed with HTTP status 401: Unauthorized

I have a asp.net c# web application with contains reports in remote processing mode. I am using the report-viewer control to render the reports. When I run the application in debug mode, I'm able to view my reports however when I publish the application to a different server I get this error message:
The request failed with HTTP status 401: Unauthorized.
My report server is on a different server than the location of my published web application. I have added new role assignment to my report server and also added to my web.config but the error persists. I think I am missing something in my aspx page for reportviewer.
Any input would be appreciated.
I'm assuming you already have set the server in your codebehind such as this
reportviewer.ServerReport.ReportServerUrl = "http://{server_ip}/reportserver";
or via the properties of the report viewer control. Make sure you change {server_ip} to the actual for the report server.
Other such problems I've seen in the past have to do with access for individual reports. Since this is cross-server, you'll need a proxy user set to view the reports.
Here are 2 examples from MSDN:
Example 1
Example 2
Yes! use Page_Load & Page_Init in this way
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ReportViewer1.Visible = True
Dim strReportsFolder As String = ConfigurationManager.AppSettings("ReportsFolder")
Dim reportName As String = "report1"
ReportViewer1.ServerReport.ReportPath = strReportsFolder + reportName
End Sub
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
PopulateReport(ReportViewer1, "")
End Sub
Public Shared Sub PopulateReport(ByVal rptViewer As ReportViewer, ByVal reportName As String)
Dim strReportServer As String = ConfigurationManager.AppSettings("ReportServer")
Dim strUserName As String = ConfigurationManager.AppSettings("Username")
Dim strPassword As String = ConfigurationManager.AppSettings("Password")
Dim strDomain As String = ConfigurationManager.AppSettings("Domain")
rptViewer.ServerReport.ReportServerUrl = New Uri(strReportServer)
rptViewer.ServerReport.ReportServerCredentials = New ReportViewerCredentials(strUserName, strPassword)
End Sub

Resources