yogesh vaidya Ответов: 0

Структуре базы данных Asp.net MVC в сущности, во-первых , контроллер [вам почта] actionresult и [HTTP-запрос POST] actionresult , не запускаются [протоколы HttpPost] actionresult и правда ошибка


В базе данных ASP.NET сущность fremwork в MVC, во-первых , контроллер [GETPOST] ActionRresult и [протоколы HttpPost] ActionResult ,
[HTTPPOST] ActionResult не запускается и хотя ошибка

когда я запускаю проект ,проект также запускается, но когда я сохраняю данные в текстовом поле и
нажмите на кнопку Создать ошибка отображается на экране

Ошибка сервера в приложении'/'. Ресурс не может быть найден. Описание: HTTP 404. Искомый ресурс (или одна из его зависимостей) может быть удален, изменено его имя или временно недоступен. Пожалуйста, просмотрите следующий URL-адрес и убедитесь, что он написан правильно. Запрошенный URL-адрес: / ,

где я должен дать url-адрес ?

Что я уже пробовал:

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")
}

F-ES Sitecore

Вам необходимо настроить контроллер по умолчанию и действие в конфигурации маршрута.

0 Ответов