Need Help with Bakery Template from WebMatrix [Answered]RSS

16 replies

Last post Jan 30, 2011 06:25 AM by bilaldadar

  • Need Help with Bakery Template from WebMatrix

    Jan 25, 2011 01:45 AM|bilaldadar|LINK

    I am studying the Bakery website template offered inside WebMatrix.

    I set my hotmail details in the code part of orders.cshtml as below.

                //Enter your Hotmail credentials for UserName/Password and a "From" address for the e-mail
                WebMail.UserName = "bilaldadar";
                WebMail.Password = "myPassWord";
                WebMail.From = "Bilal Dadar";

    I went online and ran the website from default.html and then selected some items to purchase.

    I then entered another email address as the buyer and clicked on Place Order, and I got an error message instead of success.

    How are the email details required to be entered in the code?

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 25, 2011 02:26 AM|HCamper|LINK

    bilaldadar

                //Enter your Hotmail credentials for UserName/Password and a "From" address for the e-mail
    item 1)  WebMail.UserName = "bilaldadar";
    item 2) WebMail.Password = "myPassWord";
    item 3)  WebMail.From = "Bilal Dadar";  <--- change this

    Hello,

    I am guessing that the problem is at "item 3" that is an invalid Email entry.

    A proper Email "mayname @ someplace "." com" the missing @ and the "." could be the problem.

    I say I am guessing because you did not include the other

    code that will use the label "WebMail" and  From variables.

    Post errors,issues & questions to this thread.

    Martin :)

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 25, 2011 03:32 AM|bilaldadar|LINK

    Thanks, I changed #3 to "bilaldadar@hotmail.com" and the page took several moments before returning the error message. This is the rest of the C# code in orders.cshtml:

    @{
        Page.Title = "Place Your Order";

        var db = Database.Open("bakery");
        var productId = UrlData[0].AsInt();
        var product = db.QuerySingle("SELECT * FROM PRODUCTS WHERE ID = @0", productId);

        if (product == null) {
            Response.Redirect("~/");
        }

        if (IsPost) {
            var email = Request["orderEmail"];
            if (email.IsEmpty()) {
                ModelState.AddError("orderEmail", "You must specify an email address.");
            }

            var shipping = Request["orderShipping"];
            if (shipping.IsEmpty()) {
                ModelState.AddError("orderShipping", "You must specify a shipping address.");
            }

            //If there is no error try to process order
            if (ModelState.Count == 0) {
                var body = "Thank you, we have received your order for " + Request["orderQty"] + " unit(s) of " + product.Name + "!<br/>";
                var orderShipping = Request["orderShipping"];
                var customerEmail = Request["orderEmail"];
                if (!orderShipping.IsEmpty()) {
                    //Replace carriage returns with HTML breaks for HTML mail
                    var formattedOrder = orderShipping.Replace("\r\n", "<br/>");
                    body += "Your address is: <br/>" + formattedOrder + "<br/>";
                }
                body += "Your total is $" + product.Price * Request["orderQty"].AsDecimal() +".<br/>";
                body += "We will contact you if we have questions about your order.  Thanks!<br/>";

                //SMTP Configuration for Hotmail
                WebMail.SmtpServer = "smtp.live.com";
                WebMail.SmtpPort = 25;
                WebMail.EnableSsl = true;

                //Enter your Hotmail credentials for UserName/Password and a "From" address for the e-mail
                WebMail.UserName = "bilaldadar";
                WebMail.Password = "mypassword";
                WebMail.From = "bilaldadar@hotmail.com";

                if (WebMail.UserName.IsEmpty() || WebMail.Password.IsEmpty() || WebMail.From.IsEmpty()) {
                    Response.Redirect("~/OrderSuccess?NoEmail=1");
                } else {
                    try {
                        WebMail.Send(to: customerEmail, subject: "Fourth Coffee - New Order", body: body);
                        Response.Redirect("~/OrderSuccess");
                    } catch {
                        ModelState.AddFormError("There was an error and your order could not be processed at this time");
                    }
                }
            }
        }
    }

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 25, 2011 04:04 AM|HCamper|LINK

    Hello,

    Questions could you post what the error was for both occurances.

    Based on the code it is checking for a properly formatted Email address

    and it is also check if it is a reall Email address.

    The long wait was it was looking to match a real Email address and username,password.

    The coded information you put into the code is not a valid Username,Password,From a check at live.com.

    If you have more coding issues like this I suggest the better resource is the ASP.NET Forum.

    This Fourm is more focused on IIS Services and configration.

    Thank You,

    Martin :) 

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 25, 2011 01:26 PM|bilaldadar|LINK

    Thanks, but please note that I am not familiar at all with ASP.NET, that is why I found the WebMatrix platform more to my liking.

    The username, email address and password that I supplied are true details of a real account - my own account - at hotmail.

    If the code does not provide detailed error messages, how can I debug?

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 25, 2011 04:02 PM|simtan|LINK

    When you ran the page, what was the error message you saw in the browser? It should give others a hint as to how to solve the problem.

    Also, for ASP.NET related questions, I would recommend posting the error message to the ASP.NET forums - there are more people there who will be able to answer your question quickly:

    http://forums.asp.net/1224.aspx

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 26, 2011 01:50 AM|bilaldadar|LINK

     This is the error message:

    "There was an error and your order could not be processed at this time".

    At the moment, I am unable to test the site because of this error, which I am trying to fix:

    "URL binding failure, Cannot start the website because administrative privileges are required to bind to the hostname or port."

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 26, 2011 05:51 AM|simtan|LINK

    I just tried this - I think that both WebMail.UserName and WebMail.From need to be your full e-mail address on Hotmail.

    Also, the URL binding failure may be happening if you have multiple instances of your site open in WebMatrix, multiple instances of WebMatrix, or if you had changed your port number in the Site Settings of WebMatrix. Please ensure that all instances of IIS Express (see Task Manager to check if its running) are shut down before starting WebMatrix again.

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 26, 2011 07:59 AM|bilaldadar|LINK

    Simtan, thanks a lot. I tried your suggestion to fix IIS and it worked.

    I set both the user name and from fields to my full address but it still gives the same error.

    Did it work for you? I tried sending to yahoo, gmail and  hotmail addresses without success.

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 26, 2011 06:23 PM|simtan|LINK

    After I changed those two fields to my full e-mail address (Hotmail), it did work. You might be able to see more error details if you temporarily remove the try {} catch {} blocks around that code that sends the message. As it stands, it is blocking the visibility of the actual error message.

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 27, 2011 10:34 AM|bilaldadar|LINK

    Thanks, again. I followed your tip, and when I submit the order ... nothing happened.

    The form cleared the fields and was back to square one.

    I made another project from the same template and tested it again - same problem persists.

    Would it be possible for you to use my email address on a test order?

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 27, 2011 08:27 PM|simtan|LINK

    You can temporarily remove code using comments ("//" in front of lines or "/*" and "*/" to surround a block of code). Here is that try/catch block again:

    //try {

    WebMail.Send(to: customerEmail, subject: "Fourth Coffee - New Order", body: body);

    Response.Redirect("~/OrderSuccess");

    //} catch {

    // ModelState.AddFormError("There was an error and your order could not be processed at this time");

    //}

     

    If you do this, you will see the lowest level error you might be able to see. I tried it again and I got:

    System.Net.WebException: The remote name could not be resolved: 'smtp.live.com'
     

    Might be a temporary problem... or perhaps you are behind a firewall that does not allow your machine to connect via the SMTP port (port 25).

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 28, 2011 04:34 AM|bilaldadar|LINK

    I am very sorry this is turning out to be a fiasco and I ask you be patient with me while we sort this out together.

    My computer has the basic Windows Firewall enabled so I disabled it and:

    1. Ran the website with the Try/Catch code - no error except the one set in the Catch code.

    2. Ran the website without the Try/Catch block - the form just reinitialized without any error.

    I have enabled the Firewall again.

    Any further help will be appreciated.

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 28, 2011 02:42 PM|simtan|LINK

    No problem; it is worth figuring this out for the benefit of others as well. :-)

    When I mentioned "deleting" the try/catch block, I didn't mean to delete the entire thing - as you can see above, I only commented out the lines of the try/catch block that did the 'catching'. I left the actual line that was trying to send the mail:

    WebMail.Send(to: customerEmail, subject: "Fourth Coffee - New Order", body: body);

    Response.Redirect("~/OrderSuccess");

    As for the firewall, it might not just be your Windows Firewall - it could be your router or ISP that blocks these kinds of requests.

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 29, 2011 02:32 AM|bilaldadar|LINK

    Simtan, Thanks for the encouragement.

    And how silly of me to comment out actual code lines!

    OK, I did as you directed and this is what I got:

    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 65.55.162.200:25 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.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 65.55.162.200:25

    Source Error:

    Line 48:             } else {
    Line 49: // try {
    Line 50: WebMail.Send(to: customerEmail, subject: "Fourth Coffee - New Order", body: body);
    Line 51: Response.Redirect("~/OrderSuccess");
    Line 52: // } catch {

    My IIS Server shows port no. 2836, so I changed the smtpport in the code from 25 to 2836 but still got the same error.

    I pasted http://65.55.162.200:25 in my browser and received this reply in IE, Mozilla, Chrome:

    This address is restricted.
    This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection.

    I disabled Windows Firewall and ran the website in all three browsers. This time, the browsers actually showed the progress trying to connect to localhost and after several seconds throws up the same error as above.

    Is this a timeout error?

    Experience is a bad teacher whose exams precede its lessons.
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 29, 2011 11:45 PM|simtan|LINK

    Try changing the port in the code to 587 - this is an alternative port for smtp.live.com for those whose ISP's may block that kind of internet traffic (due to concerns about sending spam, etc.)

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Need Help with Bakery Template from WebMatrix

    Jan 30, 2011 06:25 AM|bilaldadar|LINK

     Yippeee!!! It worked. Thanks a ton, buddy Sim Tan. That's the spirit of excellent support professionals.

    Experience is a bad teacher whose exams precede its lessons.