ActionMailer fail with "Value cannot be null. Parameter name: uriString" - asp.net-mvc-3

I'm trying to use ActionMailer 0.7.0 to send a email from my MVC 3 project.
I've followed the sample posted in the project site to the letter.
But when I try to send the email the following error always occurs:
"Value cannot be null. Parameter name: uriString"
It occurs the the #Url.AbsoluteAction in the email body.
#using ActionMailer.Net
#model User
#{
Layout = null;
}
Welcome to My Cool Site, #Model.FirstName
We need you to verify your email. Click this nifty link to get verified!
// The error happens in the line bellow
#Url.AbsoluteAction("Verify", "Account", new { code = #Model.EmailActivationToken.ToString() })
Thanks!
Can some one help me? What am I missing?

After struggling a few days trying to solve the problem using the code proposed in the sample I gave up.
I've download the source and found out that the problem occurs when your RouteCollection is not standard (which is my case).
So I found an elegant work around that worked for me.
Instead sending the Token to the view and use the Url.AbsoluteAction method I used the Url.Action with the protocol parameter in the controller and sended the complete url in the view model. Like this:
new EmailsController().ActivationMail(new ActivationMailViewModel { Email = data.Email, FirstName = data.Name, ActivationLink = Url.Action("VerifyEmail", "Mail", new { code = data.ActivationToken.ToString() }, "http") }).Deliver();
The view became:
#using ActionMailer.Net
#model User
#{ Layout = null; }
Welcome to My Cool Site, #Model.FirstName
We need you to verify your email. Click this nifty link to get verified!
#Model.ActivationLink
Thanks!
About the SMTP host problem, I found out that in Web.Config even if you set the deliver for "SpecifiedPickupDirectory" you need to add an empty host tag. It's not specified in any ActionMailer sample. Here is the final configuration:
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<network host="none" />
<specifiedPickupDirectory pickupDirectoryLocation="C:\temp\" />
</smtp>
</mailSettings>
</system.net>
I hope it helps someone.
Best luck for everybody.

I've just spent a couple of hours implementing ActionMailer into my MVC project.
I found Scott's screencast really helped me.
http://www.youtube.com/watch?v=QQRzYo7k9Vs&hd=1
It explains how to get round the SMTP host issue, as well as how to set up the User models etc.
I'm still getting stuck on user email verification and will try to let you know if I sort it out.
However, you don't need this to send 'ordinary' emails. So my advice would be to leave it out for now until you can get the emails working OK.
Hope that helps, and I'll be back to you when I sort out email verification!
Cheers
Chewie

Related

Web Api Help Page route

I was recently tasked with fixing one of our Help Pages that had gone down. I hadn't ever worked on one before, so I jumped in and started playing around with it. I noticed we had this route set up for the Help Page:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"HelpPage_Default",
"api/v1/Help/{action}/{apiId}",
new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
HelpPageConfig.Register(GlobalConfiguration.Configuration);
}
I compared it to another working Help Page route and found the url to be different. I changed the url to
"Help/{action}/{apiId}"
and it worked. I've done some research online (this helped) but still fail to understand why changing the url would make any difference on whether that page would be hit. It would make sense to me that if I went to mydomain.com/api/v1/Help that I would still hit the help page with the original url.
Thank you in advance.
Route what you have "api/v1/Help/{action}/{apiId}" this is wrong because format of the route should be [Controller]/[Action]/[Id] and your controller is Help not "api/v1" .
And to answer your question to "mydomain.com/api/v1/Help" this url hitting the help page, yes it will if you give "help/{action}/apidid" url in the route.
"api/v1" till here its your IIS virtual directory setup not a route in your application configuration.

Ajax.ActionLink POST doesn't work in ASP.NET MVC 5

A quick summary of the situation:
In my View I have this piece of Razor code:
#{
ViewBag.Title = "Index";
AjaxOptions options = new AjaxOptions();
options.HttpMethod = "POST";
}
...
#Ajax.ActionLink("Linkname", "CreateChallenge", new { challengedId = Model.UserId },options);
Than in my controller:
[Authorize]
[HttpPost]
public string CreateChallenge(string challengedId)
{
ChallengeRepository.CreateChallenge(challengedId);
return "Sendend!";
}
I get an 'Resource not found' error when I click the link but when I remove the [HttpPost] attribute everything works fine. But I want a POST method. I have looked around and found some similar problems but none of the solutions worked for me.
UPDATE
Spoke too soon, remembered that you need the jQuery.Ajax.Unobtrusive http://www.nuget.org/packages/jQuery.Ajax.Unobtrusive/ package
If you install this and reference it in you view it should work, it did i my OOTB test :)
Did a quick test myself, it seems you cant use Ajax.ActionLink to issue a POST request, it does a GET even though you set POST in AjaxOptions. You can see this if you use fiddlr to monitor the traffic.
You can also use the Postman extension for Chrome to test it, you will see that the action method actually behaves as it should when you POST to it. But you get the 404 because it actually does a GET
If it were me I would use jQuery to do the post. You can see more here http://api.jquery.com/jquery.ajax/

MVC3 SSL Trouble - Can't switch from HTTPS to HTTP when SSL is not required

I'm trying to get my MVC3 site to redirect from HTTPS back to HTTP when the user browses to a page where it's not required (and they aren't logged in). I Don't want to have the load of running the whole site HTTPS but it's looking like thats the way I'll have to go.
I've been having loads of trouble with remote debug and symbols, but having gone back in time to 1985 and using message box equivalents to debug with I've come to the following conclusion:
if (filterContext.ActionDescriptor
.GetCustomAttributes(typeof(RequireHttpsAttribute), true)
.Any()
)
{
return true;
}
return false;
Always returns false.
The controller def starts as:
[FilterIP(
ConfigurationKeyAllowedSingleIPs = "AllowedAdminSingleIPs",
ConfigurationKeyAllowedMaskedIPs = "AllowedAdminMaskedIPs",
ConfigurationKeyDeniedSingleIPs = "DeniedAdminSingleIPs",
ConfigurationKeyDeniedMaskedIPs = "DeniedAdminMaskedIPs"
)]
[RequireHttps]
public class AccountController : Controller
{
And it doesn't seem to work for any actions in this controller (although they do get successfully routed to SSL).
Any suggestions? I'd love to see an answer for what I perceive as my own nubery ;)
Custom NotRequreHttpsAttribute tutorial
I use the above link post to implement my custom attribute, and redirect from https to http. Hope this helps.
My problem was discovered to be related to the bindings on the server published to. We use the same server for stage and production, and the stage https bindings were not set, so whenever it was calling an https page it was resolving into our production site (which looked the same so it was hard to spot).
Once I added a binding it was all solved. My code was ok...

How to load the data using Ajax in Django template?

Using Ajax in Django is a open Issue. I have tried to understand it by reading blogs and forums, but it didn't work for me. I am posting a very simple question related to it.
Method defined in views.py: (just a sample)
def widget_data(request):
####
extra_context = {
'data': username
'part': company
}
return direct_to_template(request,'test/widgets.html',
extra_context)
I want to load extra_context to rendered template using Ajax.
Following things will happen in widget.html template i.e.
When a moderator will type a URL at the address bar to open a page it will load two widgets i.e. one for loading all the registered username and other one for their company name . user are continuously registering to the sites and adding company name to their profile. When a new user will registered to the site both widget should load automatically using Ajax.
I have no idea about the topic of Ajax.
How to do this?
How should i even start this?
I have read these following links :
Tutorial 1
Tutorial 2
I know that the answer will be too long and too messy but any help will be appreciative.
If you use jQuery you can do the following
$.get('/url/of/widget_data/view', success(data, textStatus, jqXHR) {
$('#idofdivtoupdate').html(data);
});
That would probably be the easiest way to do it.

Best PHP mailing library for Codeigniter-2

Iam using CI-2 default mail class for sending emails. But it is not sending HTML based emails properly.
Can someone tell me good email sending libraries for CI2.
Thanks in advance
Try to configure the library to send html emails
$config['mailtype'] = 'html';
$this->email->initialize($config);
gmail and HTML content is a common problem; solutions have been suggested in the official CI forum with references to using Swift Mailer instead.
There is another solution I've found for poor HTML / Email Support.
Open up the Email Class:
System/Libraries/Email.php
Around Line 51 You'll see
var $send_multipart = TRUE;
Set this to FALSE and try again. I find CI's email library to be very good.

Resources