Area in MVC3- RedirectToAction is not working as expected - asp.net-mvc-3-areas

I have an area called coverage.The routing is like
context.MapRoute(
"CoverageSummary", // Route name
"Coverage/Summary/{policyId}", // URL with parameters
new { controller = "Coverage", action = "Summary", policyId = UrlParameter.Optional }, // Parameter defaults
new string[] { "Web.Mvc.Claims.Areas.Coverage.Controllers" }
);
when I acess the page Mysite/Coverage/Summary/10 it shows a page. fine.
But in an Action methode i have code as below
return RedirectToAction("Summary","Coverage", new RouteValueDictionary(new { policyID = 10 }));
but this is not loading the page Mysite/Coverage/Summary/10 .
it is showing 404 error.
if i refresh the page still it give 404.but if i cut and past the same url in address bar and hit enter it works
What can be the reason

Try with area property in your RouteValueDicitionary
return RedirectToAction("Summary","Coverage", new RouteValueDictionary(new { policyID = 10, area = "Your_Area_Name" }));

Related

In AEM how to add a new node called “listeners” in the component dialog ,without using dialog.xml file

Actaully i am using "before submit" listener to do some validation for my selection box
I have reffered the following link:
https://helpx.adobe.com/experience-manager/using/classic_dialog_validation.html.
But "before submit" method calling only when i place ,
dialog listener in the dialog root level only.
how to place dialog listener in dialog root level(I checked in my project there is no dialog.xml file ,they using only java code to construct component dialog).
Can anyone please help me in this ?enter image description here
Dialog property construction code :
#DialogField(name ="./validateProgram",
fieldLabel = "Validate Program",
fieldDescription = "(synchronized)",
additionalProperties = {
#Property(renderIn = Property.RenderValue.TOUCH,
name = "validation",
value = "validation-program")
},
listeners = {
#Listener(name ="beforesubmit",
value = "function(dialog){" +
"return programValidation.beforeSubmit(dialog);"+
"}")
})
#Selection(
type ="select",
optionsProvider = " ",
dataSource = "/resourcetype/data")
public final String validateProgram;
Java Script code:
window.onload = function() {
programValidation.init();
};
var programValidation= programValidation|| (function($) {
function initialize() {
};
function validate() {
alert("inside validate method");
var res = true;
return res;
};
return {
beforeSubmit: validate,
init: initialize
}
})(jQuery);
You are using the cq component maven plugin this a very vital piece of information to get your question answered.
I have not used this plugin before, but in your case, I assume you are looking for the Listener annotation where you can set the name as beforesubmit and the value as function(){alert(1)}
you'll probably have to set the annotation on a local variable similar to how you would annotate a dialog field '#DialogField', find more docs in the plugin's usage page here: http://code.digitalatolson.com/cq-component-maven-plugin/usage.html
Hope this helps.
Thanks for your support. Found the following way to solve the issue .
I added ValidateFields method from within the 2 listeners (FIELD_LISTENER_LOAD_CONTENT and FIELD_LISTENER_SELECTION_CHANGED)
function ValidateFields(dialog) {
dialog.on("beforesubmit", function(e) {
if(<condtion failed>)
CQ.Ext.Msg.alert(CQ.I18n.getMessage("Error"), CQ.I18n.getMessage("<error message>"));
return false;
} else {
return true;
}
}, this);
}

Identity Server 3 Reset Password Page

Identity Server v3 Custom Page Reset Password
I am doing the very same thing except I am working from the Mvc View Service example. I cannot figure out how I need to modify the MvcViewService and LogonWorkflowController to add the reset password page / view.
Any assist is greatly appreciated.
In MvcViewService class you have to change implementation of public Task<Stream> Login(LoginViewModel model, SignInMessage message) method.
Below code example adds two custom links to Login page:
Reset password
Register
public Task<Stream> Login(LoginViewModel model, SignInMessage message)
{
model.AdditionalLinks = new List<LoginPageLink>()
{
new LoginPageLink()
{
Text = "Reset password",
Href = "resetpassword"
},
new LoginPageLink()
{
Text = "Register",
Href = "register"
}
};
return this.GenerateStream(
model,
message,
"login",
() => this.defaultViewService.Login(model, message));
}
This is how it looks:

MVC routing is not working sometimes

I have routing in MVC 5 as:
context.MapRoute(
"cart_contact",
"Cart/MyContact",
new { controller = "Shopping", action = "MyContact" }
);
context.MapRoute(
"cart_shipping",
"Cart/MyShipping",
new { controller = "Shopping", action = "MyShipping" }
);
context.MapRoute(
"cart_payment",
"Cart/MyPayment",
new { controller = "Shopping", action = "MyPayment" }
);
context.MapRoute(
"cart_default",
"Cart",
new { controller = "Shopping", action = "Index" }
);
when I have Url as: /Cart/MyContact, sometimes I'm hitting "MyContact" action, sometimes I'm hitting "Index" action, "MyShipping" and "MyPayment" has same problem too, sometimes hitting the "MyShipping" or"MyPayment" action, but sometimes hitting "Index" action, could anybody help me check what's wrong with my routing? what I want is those different endpoint should always hit different action.
Your help is great appreciated.
Thanks
Oreo

UI5 navContiner bindAggregation not loading the pages

i need to build the page by binding aggregation as below
view
<NavContainer
id="navCon"
class="navContainerControl sapUiSmallMarginBottom" height="50%">
</NavContainer>
controller
onInit : function()
{
var navCon = this.getView().byId("navCon");
navCon.bindAggregation('pages',{
path:'/pages',
factory : jQuery.proxy(this.createPages,this)
});
}
createPages : function(sid,context)
{
var eachpageData = context.getObject();
var grid = new sap.ui.layout.Grid({
defaultSpan:"L4 M6 S6"
});
var page = new sap.m.Page({
id : eachpageData.name,
title : eachpageData.name,
content : grid
});
grid.bindAggregation('content',{path:'data',factory :this.createPageContent});
return page;
},
But when i see from the debugger it has only one page
But when i call navto
handleNav : function(evt)
{
var navCon = this.getView().byId("navCon");
var target = evt.getSource().getText();
if (target) {
//var animation = this.getView().byId("animationSelect").getSelectedKey();
navCon.to(this.getView().byId(target));
} else {
navCon.back();
}
}
and if i see the navCon.getPages() will give 2 pages.
What mistake i have done here?
You are trying to pass the DOM element to the NavContainers.to(DOM) method. This is where its gone wrong.
But NavContainers.to() method can accept id(String) as parameter.
Change your handleNav method as follows it will work.
handleNav : function(evt)
{
var navCon = this.getView().byId("navCon");
var target = evt.getSource().getText();
if (target) {
navCon.to(target);
} else {
navCon.back();
}
}
NavContainers can display only one page. You can add more pages to the pages aggregation, but they will be visible only if a navigation event is fired with the proper parameters. After that, the layout of the new page is loaded and added to the DOM.
In case of SplitApp, application can display two pages (master and detail) if you see it on tablet or desktop; however it's implemented by the use of two NavContainers.
That's why the control inspector returns with one page before the navigation, second page is not part of the DOM until you navigates to it.
If you place a breakpoint into your code instead of using the control inspector, you can call the navCon.getPages() which should return with the number of pages in the aggregation.

How to create a simple landing page in MVC2

I'm trying to create a http://domain.com/NotAuthorized page.
went to Views\Shared and added a View called NotAuthorized witch originates the file name NotAuthorized.aspx
in my Routes I wrote
routes.MapRoute(
"NotAuthorized", // Route name
"NotAuthorized.aspx" // Route Url
);
but every time I access http://domain.com/NotAuthorized I get an error
The resource cannot be found.
What am I missing?
How can access this without using View("NotAuthorized") in the Controller, in other words, not passing through any controller.
You can't access views directly without passing through a controller. All pages in the Views folder cannot be served directly. So one way to accomplish what you are looking for is to write a custom[Authorize] attribute and set the error page:
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
base.HandleUnauthorizedRequest(filterContext);
}
else
{
filterContext.Result = new ViewResult { ViewName = "NotAuthorized" };
}
}
I still have no idea on how to accomplish it, but what I did was use the Home Controller and create an Action called NotAuthorized
public ActionResult NotAuthorized()
{
return View();
}
And add a route like
routes.MapRoute(
"NotAuthorized", // Route name
"NotAuthorized", // URL with parameters
new { controller = "Home", action = "NotAuthorized" } // Parameter defaults
);
And works fine now, I can easily redirect in any part of my Business Logic to /Notauthorized and that will route fine.