Application doesn't read action result method in MVC3 - forms

We are using MVC3 and we are trying to create a method in a Controller named UserSesionManager. This method is called from
#using (Html.BeginForm("GetStatTypesDistribution", "UserSesionManager", FormMethod.Post, new { enctype = "multipart/form-data" }))
In the UserSesionmanager Controller we have:
[HttpPost]
public ActionResult GetStatTypesDistribution(FormCollection form)
However when we call it we get this error:
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: /UserSesionManager/GetStatTypesDistribution
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Also, whe I add a breakpoint it says that the sourcecode is different form the original version. I follow the instructions of right clicking on location but, the error still exists.
Why is this happening, and how can we fix this?
Thanks a lot!

Make sure that the controller is named UserSesionManagerController and not only UserSesionManager:
public class UserSesionManagerController: Controller
{
...
[HttpPost]
public ActionResult GetStatTypesDistribution(FormCollection form)
{
...
}
}
Also make sure that you have a default route in global.asax:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Rebuild your solution. Stop the web server you are using for debugging and check to ensure if you are using the built in web server (Cassini) it's not running in the system tray.
F5 in visual studio to debug. If you still get the error load up the modules window from debug menu then modules. Find your code listed in there an look where it's loaded from.
If it's still an issue delete the apps folder from the temporary asp.net files folder and try debugging again but the modules window should give some info.

Related

Response redirect using IP in dotnetnuke

I am hosting and developer on my DNN portal. I need to redirect users using client IP. I think may be two ideas for this work.
1- DNN Setting
Maybe DNN has settings for it that I can set specific URL for client IP addresses and automatically DNN redirects to specific URL.
I read many topic but I could not find setting to do it.
Is there a way to do this?
2- New Module
I have a ascx that onload method has this code:
var IP = Server.HtmlEncode(Request.UserHostAddress).ToString();
using (Entities db = new Entities())
{
var retVal = db.URLAddresses.Where(u => u.IPAdress == IP).FirstOrDefault();
if (retVal != null)
Response.Redirect(retVal.URL);
}
But I should add this code to any ascx for redirect using client IP. This is impossible because maybe I haven't source code modules.
I think I should create new module. So I can add it to page. Module changes onload page and redirect to URL using client IP.
In this scenario, I try to create new module but I don't know how I can change onload method each page that is added module to it?
You can use IHttpModule and make a new Module for Including your class then you should add your IHttpModule to web.config .
For e.g
<add name="YourModule" type="YourAssembly, YourNameSpace" preCondition="managedHandler" />
See this Sites:
HTTP Handlers and HTTP Modules Overview
and How To Create an ASP.NET HTTP Module
DNN does have a Host setting that will allow or deny access to users logging in based on their IP address. It's in Host Settings > Advanced Settings > Login IP Filters. I don't think that will give you the desired result.
I would not suggest creating a module. It can be difficult copying it to all pages and ensuring one instance is added to every page.
Rather, I would create a skin (theme) token. To do this, create a simple class library project. Create an .ascx and ascx.cs file. You can leave the .ascx empty because you don't have any html to add to the pages. In the .cs, put something like this:
namespace MyCompany.DNN.Skin
{
public partial class IpRedirect : SkinObjectBase
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Put your redirect logic here
}
}
}
Then, in your theme/skin ascx pages, include the following:
<%# Register TagPrefix="myco" TagName="IPREDIRECT" Src="~/DesktopModules/MyCompany/IpRedirect/IpRedirect.ascx" %>
<myco:IPREDIRECT ID="pageRedirect" runat="server" />
This will ensure that this functionality will execute on all pages in the site that use the skin/theme.

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.

Piranha CMS - How to view individual posts when Prefixless Permalinks in use

We're using Piranha CMS with the following setting:
<prefixlessPermalinks value="true" />
However this breaks individual posts urls generated using the Permalink helper e.g.
#UI.Permalink(post.PermalinkId)
With prefixlessPermalinks set to False this would normally be the url that is generated: /home/1st-test-blog-entry
With prefixlessPermalinks set to True the url generated becomes:
/1st-test-blog-entry (the "home" has been removed as it's prefixless)
Following a prefixless url generates the following exception:
System.Web.HttpException: Cannot use a leading .. to exit above the
top directory.
Any ideas how to circumnavigate this issue?
Attempted workarounds:
I manually prefix "/post" to the permalink generated then I added the following route mapping which catches the request:
routes.MapRoute(
name: "Post",
url: "post/{permalink}",
defaults: new { controller = "Post", action = "Index", permalink = UrlParameter.Optional },
namespaces: new[] { "Maps.Portal.Controllers" }
).DataTokens["UseNamespaceFallback"] = false;
The following controller catches the request:
public ActionResult Index(string permalink)
{
var model = GetModel(permalink);
return View(model.GetView(), model);
}
But fails as the readonly SinglePostController.CurrentPermalink property isn't being populated and so causes Piranha CMS to throw an exception. It may be interesting to note that this controller fires correctly when the draft version of the post is being viewed as the CurrentPermalink is being populated by the CMS.
After experimentation I can confirm that the issue isn't with Piranha CMS, but with the MVC shared layout. Still trying to track it down, but stripping out everything apart from the CMS content allows the post page to be shown.
Update:
I finally tracked it down to multiple uses of #Url.Content(url). Very bizarre as all seem to be valid urls e.g. #Url.Content("~/Content/images/ios/57x57iOS.png"). Once these were all removed then the page would render correctly!?
Discovery:
This issue turned out to be a development environment only issue for me...
Running the site in Visual Studio Development Server from VS2012 results in this error, but once the web application was deployed to IIS8 the issue disappeared.
I can't reproduce your error with either MVC or Web Pages, in fact we use prefixless permalinks in almost all live installations I've deployed. I started up the MVC template, installed a fresh database and added a post with your specified title/permalink and it shows up without issues with prefixless permalinks.
How have you set up your installation?
Regards
/HÃ¥kan

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();
}

ASP.Net MVC 2 Forms Authentication cookieless = "UseUri" while submit authorization fails

I just started working with ASP.Net MVC 2.
I created a new ASP.Net MVC application and created one vehicle controler with a database table connected with LINQ. Then created forms authentication mechanism for the application and tried to use the uri instead of cookies it was working smoothly but when i submit the form by creating a "Create" view from the controler using the utility it just dont work. The autherization got failed and asking to enter the user name and password again.I had created the authorization mechanism by adding Authorise attribute to the Controller so as to get authorized for all the actions.
namespace MVCNEW.Controllers
{
[Authorize]
public class VehicleController : Controller
{
But if i use the cookies instead of uri it works fine.
Thanks in advance...
Please see http://forums.asp.net/p/1517391/3634908.aspx for an official response.
Summary: Cookieless Session support is essentially obsolete, and the MVC framework isn't likely to include additional support for it.
I found the problem and a solution.
This was due to some error in the framework. They are not creating the Uri string for the Form action while calling
Html.BeginForm()
But if we make it call overloading of this method like the providing the Controller name and Action name it is working fine.
view plaincopy to clipboardprint?
Html.BeginForm("Create","Vehicle")