locked
POST Error on Register RRS feed

  • Question

  • User-1641868886 posted

    I have implemented Email confirmation to ASP.Net authentication in "Register" controller in MVC site. Working from MSFT tutorial page referenced in the "Register" method, using the samples of the method and the "SendMail" code to be implemented in "IdentityConfig" and learning how it works. 

    I tested in localhost. I got 1) full implementation including 2) redirect to "Info" in shared views ("Email Sent. Please check your Email and confirm....") , 3) properly formatted Email with link, 4) link/url back to "Accounts/ConfirmEmail" and 5) able to login with new user Email confirmed=true.

    Problem:  I have now deployed to my production/hosted site. This is on GoDaddy shared hosted site. What happens is:  1) the new user IS posted and written to the AspNetUsers table, 2) I am NOT redirected to "Info" and 3) in Devtools, I am seeing the following:

    POST https://docscost.com/Account/Register 500 (Internal Server Error)

    ...with an Error on the "Register" view. Above error references "Register:1" which is the first line, "<!DOCTYPE html>" with no apparent explanation on what is causing. I admit I am not fully versed on devtools and debugging, but without access to the controller method in the hosted environment, I have no idea how to find out what is happening. What I have considered and tried are:

    1) need for a "<machinekey />" in web.config ?

    2) need to add "<httpCookies httpOnlyCookies="true" requireSSL="true" />" to web.config ?

    3) ensure that "<allow users="*" />" is added for "Info" in web.config to ensure "Register" can post/redirect to it ?

    Here is the code I am using for the "Register" method.

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken] public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "<a href=\"" + callbackUrl + "\">Confirm</a>"); ViewBag.Message = "Please check your email and confirm your account to log in."; return View("Info"); } AddErrors(result); } return View(model); }

    Plz advise if you see anything. I can post the "void SendMail" from IdentityConfig although it seems to only have to do with formatting the email body, naming the email client, etc.

    Thanks much,

    RC

    Wednesday, May 6, 2020 7:44 PM

Answers

  • User475983607 posted

    My best guess is the send email method is failing but it is impossible really know without the error that caused the 500.  How about adding error handling and logging so you can get the actual error?

    You can also remove (comment) the send email method to see if the error stops.   Then you'll know if the email process is causing the exception.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 6, 2020 9:24 PM

All replies

  • User475983607 posted

    My best guess is the send email method is failing but it is impossible really know without the error that caused the 500.  How about adding error handling and logging so you can get the actual error?

    You can also remove (comment) the send email method to see if the error stops.   Then you'll know if the email process is causing the exception.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 6, 2020 9:24 PM
  • User1535942433 posted

    Hi ReidMelSam,

    Accroding to your description,as far as I think,I suggest you could get the details error in web.config,just like this:

    <configuration>
    	<system.webServer>
    		<httpErrors errorMode="Detailed" existingResponse="PassThrough"/>
    	</system.webServer>
    </configuration>

    Best regards,

    Yijing Sun

    Thursday, May 7, 2020 8:16 AM
  • User-1641868886 posted

    Thanks much, Joe...

    I got a detailed stack, the first line may give me a clue, highlighting as follows:

    [SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions xxx.xxx.xx.xx:587]

    ...where "587" is the port no. For the mail service I am sending from, the smtp tutorial states "Alternatice Port Number: 465 (With SSL/TLS)"

    so the first thing will be to use their desired port no. 465 and re-compile to see if that's all it is. But your instinct seems right, merely a failure to send email error. I'll do this and report what I see. Thanks again for now!

    RC

    Thursday, May 7, 2020 5:38 PM
  • User-1641868886 posted

    To yij sun:

    Thanks but that threw my entire application into server error. Don't know my way around this command in web.config yet, so gonna go with per the other comment for now. Appreciate the help!

    RC

    Thursday, May 7, 2020 5:39 PM
  • User475983607 posted

    There a many reasons for this error; Virus checker, firewall, another process is blocking the port.  Contact your hosting provider for assistance.  

    Thursday, May 7, 2020 6:14 PM
  • User-1641868886 posted

    Okay, I got past all that. MUCH that I did not understand about my particular setup. I previously had built up MX records on my hosting environment (GoDaddy) for my email server (zoho) but did not realize I should go DIRECT from the hosting smtp as the MX records are there to handle the "handshake." So trying to use "smtp.zoho.com" as the server did not work at ALL, obviously. Their server either refused connection from the host, or it timed out.

    I revised with the appropriate hosting smtp server info, then the email went through fine.

    Secondary issue:   I have to learn how to get the email to appear in MOST users' inbox (tested w/ my gmail) without a lot of scary SPAM warnings about the email and the "Confirm" link. I initially had an error stating that "secure connections are not supported" so I had to revise the "SendMail" as follows:

    from:
    
    smtpClient.EnableSsl = true;
                smtpClient.Send(msg);
    
    To:
    
    smtpClient.EnableSsl = false;
                smtpClient.Send(msg);

    I will look for any documentation by other users on this, or if you know any such info, plz advise. I'm wondering if the issue is:  a) external email server, b) GoDaddy smtp server, or c) settings in my own code/web.config, etc.

    Thanks,

    RC

    Tuesday, May 12, 2020 2:21 PM