Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET MVC entity fremwork DATABASE first , CONTROLLER [GETPOST] ActionRresult AND [HTTPPOST] ActionResult ,
[HTTPPOST] ActionResult DO NOT RUN and though error

when i run the project ,project run as well but when i file data in textbox and
click on create button Error shown on screen

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: / ,

where i should give url ?

What I have tried:

C#
code for controller  <pre lang="c#">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
using appLogin.Models;
using LoginTut.Models;

namespace LoginTut.Controllers
{
    public class UserController : Controller
    {
        // GET: User/Registration
        //REgistration Action
        [HttpGet]
        public ViewResult Registration()
        {
            return View();
        }
          // Registration post Action 
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Registreation([Bind (Exclude = "IsEmailVerified,ActivationCode")]appLogin.Models.User user)
        {
            bool status = false;
            string message = "";

            //
            // Model Validation
            if (ModelState.IsValid)
            {
                #region //Email is already Exit 
                var Isexit = IsEmailExit(user.EmailID);
                if (Isexit)
                {
                    ModelState.AddModelError("EmailExits", "Email Alredy Exit");
                    return View(user);
                }
                #endregion

                #region  Genrat activation code 
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region Password hashing
                user.PAssWord = Crypto.Hash(user.PAssWord);
                user.ConfirmPAssWord = Crypto.Hash(user.ConfirmPAssWord);
                #endregion
                user.IsEmailVerified = false;
                #region Save to Database 
                using (MydatabaseEntities  dc = new MydatabaseEntities ())
                {

                    dc.Users.Add(user);
                    dc.SaveChanges();
                    //send emali to users
                    SendVerificationLinkEmail(user.EmailID, 
                     user.ActivationCode.ToString());
                    message = "Registration successfully Done. Account activation link 
                    " + "has been send to your email Id "+ user.EmailID ;
                    status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request ";
            }
            ViewBag.Mesage = message;
            ViewBag.status = status;
            return View();
        }
        //verify Email
        //Verify Email link
        //login
        //login post
        //loguot
        [NonAction]
        public bool IsEmailExit(string emailID)
        {
            using (MydatabaseEntities dc = new MydatabaseEntities ())
            {
                var v = dc.Users.Where(a => a.EmailID == emailID).FirstOrDefault();
                return v == null ? false : true;

            }
        }

        [NonAction]
        public void SendVerificationLinkEmail(string emailid, string activationcode)
        {
            //var scheme = Request.Url.Scheme;
            //var host = Request.Url.Host;
            //var port = Request.Url.Port;
            var verifyurl = "/User/VerifyAccount/" + activationcode;
            var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyurl);
            var fromEmail = new MailAddress("yvmail.acc@gmail.com", "SystimPArtner");
            var toEmail = new MailAddress(emailid);
            var fromEmailPAssword = "**********";
            string subject = "Your Account is Successfully created! ";

            string body = "<br> <br> We are extited to tell you that youer account is " +
                "successfully Created. Pleasae Click on the bellow link to veryfay your Account " +
                "<br> <br> <a href=""+link+"">"+link+" </a>";

            var smtp = new SmtpClient
            {
                Host="smtp.gmail.com",
                Port=587,
                EnableSsl=true,
                DeliveryMethod=SmtpDeliveryMethod.Network,
                UseDefaultCredentials=false,
                Credentials=new NetworkCredential(fromEmail 
 .Address,fromEmailPAssword)
            };
            using (var message = new MailMessage(fromEmail, toEmail)

            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })
                smtp.Send(message);
         }
    }
}



code for view cshtml
@model  appLogin.Models.User

@{
	ViewBag.Title = "Registration";
}

<h2>Registration</h2>
@if (ViewBag.status != null && Convert.ToBoolean(ViewBag.status))
{
	if (ViewBag.Message != null)
	{
		<div class="alert alert-success  ">
			success!@ViewBag.Message
		</div>
	}

}
else
{

	using (Html.BeginForm("Registration", "User", FormMethod.Post)) //"Registration", "User", FormMethod.Post
	{
		@Html.AntiForgeryToken()

		<div class="form-horizontal">

			<hr>
			@Html.ValidationSummary(true, "", new { @class = "text-danger" })
			<div class="form-group">
				@Html.LabelFor(model => model.FirstNAme, htmlAttributes: new { @class = "control-label col-md-2" })
				<div class="col-md-10">
					@Html.EditorFor(model => model.FirstNAme, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.FirstNAme, "", new { @class = "text-danger" })
				</div>
			</div>

			<div class="form-group">
				@Html.LabelFor(model => model.LAstName, htmlAttributes: new { @class = "control-label col-md-2" })
				<div class="col-md-10">
					@Html.EditorFor(model => model.LAstName, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.LAstName, "", new { @class = "text-danger" })
				</div>
			</div>

			<div class="form-group">
				@Html.LabelFor(model => model.EmailID, htmlAttributes: new { @class = "control-label col-md-2" })
				<div class="col-md-10">
					@Html.EditorFor(model => model.EmailID, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.EmailID, "", new { @class = "text-danger" })
					@Html.ValidationMessage("EmailExits", new { @class = "text-danger" })
				</div>
			</div>

			<div class="form-group">
				@Html.LabelFor(model => model.DateOFBirth, htmlAttributes: new { @class = "control-label col-md-2" })
				<div class="col-md-10">
					@Html.EditorFor(model => model.DateOFBirth, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.DateOFBirth, "", new { @class = "text-danger" })
				</div>
			</div>

			<div class="form-group">
				@Html.LabelFor(model => model.PAssWord, htmlAttributes: new { @class = "control-label col-md-2" })
				<div class="col-md-10">
					@Html.EditorFor(model => model.PAssWord, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.PAssWord, "", new { @class = "text-danger" })
				</div>
			</div>

			<div class="form-group">
				@Html.LabelFor(model => model.ConfirmPAssWord, htmlAttributes: new { @class = "control-label col-md-2" })
				<div class="col-md-10">
					@Html.EditorFor(model => model.ConfirmPAssWord, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.ConfirmPAssWord, "", new { @class = "text-danger" })
					|
				</div>
			</div>

			<div class="form-group">
				<div class="col-md-offset-2 col-md-10">
					
					@*<a>User/Registration</a>*@
					@**@
					
				</div>
			</div>
		</div>

		if (ViewBag.Message != null)
		{
			<div class="alert alert-danger ">
				Error!@ViewBag.Message
			</div>
		}
	}


}



<div>
	@Html.ActionLink("Login", "Login")

</div>
@**@

@section Scripts {
	@Scripts.Render("~/bundles/jqueryval")
}
Posted
Comments
F-ES Sitecore 14-Dec-18 5:43am    
You need to set up a default controller and action in the route configuration.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900