How do I turn off request validation in MVC2? - asp.net-mvc-2

I needs to find a way to allow html tags in MVC2 model binding.
In MVC3 there is a way but MVC2 I dont know. can you help?
In MVC3
[AllowHtml]
public string SomeProperty{ get; set; }
I need some alternate method for AllowHtmlAttribute in mvc2

You could use the [ValidateInput(false)] attribute on the controller action:
[ValidateInput(false)]
[HttpPost]
public ActionResult SomeAction(MyViewModel model)
{
...
}
This will disable input validation for all properties of the model. There's no way in ASP.NET MVC 2 to do this per property - it has to be for the entire request.

Related

Xamarin Forms Webservice soapheader always empty

I need to consume asmx webservices from a Xamarin Forms app (ios and Android). Yes, I know asmx is outdated, but I can't do otherwise.
So I add the webservice with the add 'connected services' to the main Xamarin Forms project, since there is no "add web service" menu item there. I use the second menu item 'Microsoft WCF web service reference provider". I correctly select the asmx service, configure it and everything looks in order.
Now when I consume a webservice method that has a header (TestHeader class, let's say it has a TestString in it), on the webservice the header object has default values (TestString is null).
The weird thing is that if I create a similar desktop project, do the same exact configuration steps (add connected services, etc), the Reference.cs and json code generated is the exact same, but the soapheader gets correctly passed to the webservice !
[Serializable]
public class TestHeaderClass : SoapHeader
{
public int TestInt { get; set; }
public string TestString { get; set; }
}
public TestHeaderClass TestHeader { get; set; }
[WebMethod][SoapHeader("TestHeader")]
public string HelloWorld()
{
return TestHeader.TestString;
}

How to configure resetpassword

I am using IdentityServer3 for authentication. Users are stored using AspnetIdentity framework. I wanted to provide reset password functionality to users. I want to provide this functionality in IdentityServer hosting application. I have gone through several posts here here here and this what I have done so far:
1>I have created custom user service derived from AspNetIdentityUserService.
2>Created resetpassword.html and put it in template folder. (documentation)
3>It's not necessary to create a CustomViewService, so I added LoginPageLink in AuthenticationOptions and now the link is available on login page.
4>Created ResetPasswordController
public class ResetPasswordController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ResetPassword(string username)
{
// call customservice here and reset password
return View();
}
}
Issue
when i click on the resetpassword link, i get error
The view 'Index' or its master was not found or no view engine
supports the searched locations. The following locations were
searched: ~/Views/resetpassword/Index.aspx
~/Views/resetpassword/Index.ascx ~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx ~/Views/resetpassword/Index.cshtml
~/Views/resetpassword/Index.vbhtml ~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
I know why the error is, its because we don't have corresponding view in Views folder where MVC framework in looking for. My view resetpassword.html is in template folder. And that's the confusion. Identity server is using Angular to build its views.
If I decide to use angular then
1>How do I create and pass model to resetpassword.html.
2>How do I wire-up my CustomUserService to controller.
If I use ASP.NET MVC then
1>I need to add resetpassword.cshtml in Views folder and also a new Layout.cshtml in shared folder.
2>Doing so MVC scafolding will add bootstrap resources (css,js, jquery). The version may not match with IdentityServer's embedded resources.
I am comfortable coding ASP.NET MVC but worried adding bootstrap resources twice in the solution.
What is the best and easy approach here. Any sample example will be greatly appreciated.

AutoCompleteExtender not working in DotNetNuke

I am using DNN 6.0 and VS2008 AjaxControl Tool kit 3.5
I am trying to add ASP.NET AutoCompleteExtender to a text box in one of my modules in DNN.
As far as I know the AutoCompleteExtender works only through a webservice.
I've added a webservice, but I can not get the AutoCompleteExtender to work, I get no errors but the webservice never gets invoked, What am I missing or how can I get the ASP.NET AutoCompleteExtender to work?
Thank You
In my case it was the following problem:
ERROR MSG: Only Web services with a [ScriptService] attribute on the class definition can be called from script.
Try to put [ScriptService] as a definition of your web service class.
Example:
[WebService(Namespace = "http://dnndev/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class BusinessDataProvider : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod]
public string[] GetSpecificListOfContributors(string prefixText, int count)
{
return ContributorController.GetSpecificListOfContributors(prefixText, count);
}
}
I hope this one will help you.
Best,

view not found? in asp.net mvc2

i've a Welcome.aspx in my Customer( Views )folder. but when i redirect the view from my c# coding it finds the below error message.
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: /Customer/Welcome
what would be the reason for the error?
Can you provide code how you call the view? If you are using
return View();
then you should provide just a name of view:
return View("Welcome");
adding to what #dampe said... if you are just doing a "Get" request, you will also need an
Index() ActionResult in your controller for your "Welcome" View. Your code would be similar to:
public ActionResult Index()
{
return View();
}

Is it possible that each areas on MVC2 run on separate IIS website?

Lets say I want my Admin (area) to run on HTTPS
and the default site runs on HTTP.
Is this possible? How?
How to force SSL in MVC 2.0
public AccountController: Controller{
[RequireHttps(Order=1), Authorize(Roles="Users",Order=2)]
public ActionResult Login(){
// Add login logic
return View();
}
}
The only other thing you will need to do is setup your SSL cert in IIS, but don't require it if you only want to use it in certain areas/controllers/functions.