I have a txt file named signup.txt and i want it to be sent when a user signs up like when when you sign up for a website you get a signup welcome
i have the following code to do the job
this code signs up the user
public ActionResult Signup(string username, string password, string email)
{
//using (new CodeBenchmark())
{
JsonResult result = new JsonResult();if (Globals.DisableSignup)
{
result.errorMessage = "User signup is currently disabled. Try back later";
}
else if (string.IsNullOrEmpty(username))
{
result.errorMessage = "User name cannot be blank.";
}
else if (string.IsNullOrEmpty(password))
{
result.errorMessage = "Password cannot be blank.";
}
else if (password.Length < UserManager.MinRequiredPasswordLength)
{
result.errorMessage = string.Format("Password must be {0} character long.",
UserManager.MinRequiredPasswordLength);
}
else if (string.IsNullOrEmpty(email))
{
result.errorMessage = "Email cannot be blank.";
}
else if (!Globals.IsValidEmail(email))
{
result.errorMessage = "Invalid email address.";
}
else if (!Globals.IsValidUsername(HttpContext, username))
{
result.errorMessage = "Invalid User name.";
}
else
{
try
{
MembershipCreateStatus status;
MembershipUser user = UserManager.CreateUser(username, password, email, null, null, true, null,out status);if (user == null)
{
throw new MembershipCreateUserException(status);
}
//The following check is required for TDD if (HttpContext != null)
{
FormsAuthentication.SetAuthCookie(username, false);
try
{
//Only send mail when we are not running the unit test.
SendSignupMail(username, password, email);
result.isSuccessful = true;
}
catch (Exception e)
{
result.errorMessage = e.Message;
}
}
else
{
result.isSuccessful = true;
}
}
catch (MembershipCreateUserException e)
{
result.errorMessage = e.Message;
}
}
return View("Json", result);
}
}
and this one send the email
private void SendSignupMail(string userName, string password, string email)
{
const string CacheKey = "signupMailTemplate";
var body = HttpContext.Cache[CacheKey] as string;if (body == null)
{
var file = System.Web.HttpContext.Current.Server.MapPath("~/MailTemplates/Signup.txt");
body = File.ReadAllText(file);
HttpContext.Cache[CacheKey] = body;
}
body = body.Replace("<%UserName%>", userName);
body = body.Replace(
"<%Password%>", password);SendMail(email, "Kigg.com: Signup", body);
}
but there is an error with
body = File.ReadAllText(file);
it says that
System.Mvc.Web.Controler.File(string, string, string)'is a' Method,' which is not valid in the given context
does anybody know how to fix this please help