Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET .NET WebForms , +
hey guys i am new to this asp.net stuff. I have a .aspx page which has a function something like this. this function is getting called from page_load event as shown below.
 
<pre lang="c#">
 
//page load event
try
   {
       Response.Write(SendMessages());
   }
   catch(Exception excep)
   {
 
   }
 
// SendMessage definition
    try
    {
        string response = "";
        string user = Request.QueryString["username"].ToString();
        string pass = Request.QueryString["password"].ToString();
        string mobilenos = Request.QueryString["mobileno"].ToString();
        string msg = Request.QueryString["message"].ToString();
 
        if (string.IsNullOrEmpty(user) || !user.Equals("aamir"))
            response = "User not valid.";
        else if (string.IsNullOrEmpty(pass) || !pass.Equals("1234"))
            response = "Password not valid.";
        else if (string.IsNullOrEmpty(mobilenos))
            response = "Mobile number(s) not supplied.";
        else if (string.IsNullOrEmpty(msg))
            response = "Message not supplied.";
        else
            response = "Message Sent.";
    }
    catch (Exception excep)
    {
        response = "Sending Failed";
    }
    return response;
}
this page is on localhost and running perfectly fine. I have website which calls this page as an webrequest
 
// my function to
try
    {
        string  mobile = sendsms.Send("http://localhost/testing/sendmessage.aspx?username=abcd&password=1234&mobileno=xxxxxxxxx&message=help");
    }
        catch(Exception excep)
        {
        }
    }
 
public string Send(string url)
{
 
    string retVal = null;
    try
    {
 
        // creating a request to the server
        request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
 
        // hitting the server with the request.
        writer = new StreamWriter(request.GetRequestStream());
        writer.Flush();
        writer.Close();
 
        // getting the response to the above request and reading the response from the stream.
        response = (HttpWebResponse)request.GetResponse();
        reader = new StreamReader(response.GetResponseStream());
        retVal = reader.ReadToEnd();
        reader.Close();
    }
 
    catch (Exception excep)
    {
        retVal = null;
    }
 
but i m getting error : The remote server returned an error: (401) Unauthorized.
Posted 1-Apr-13 0:25am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Right click on testing folder. security -> allow permission to user'Network Service'
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100