Click here to Skip to main content
12,394,573 members (73,671 online)
Rate this:
 
Please Sign up or sign in to vote.
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 31-Mar-13 23:25pm

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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2016
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