Return err view is not working - asp.net-mvc-5

I have a controller that has a return type of void. Is there any way which I can redirect this controller to an error view page?
I try many things but its not worked for me like create error page and return it like
return View("Error");
Thanks!

Please try to use the following:
System.Web.HttpContext.Current.Response.Redirect
Good luck!
Shimi

Related

Access Selenium LocalStorage nodejs

Im trying to retrieve a value from a key using selenium, i've been searching for hours without anybody or anything telling me how i could do that,
What im trying to retrieve looks like this which i obtained while typing F12 : https://i.imgur.com/xYSHnnC.png
Which is on the client side.
You can use this:
driver.executeScript(
"localStorage.getItem(arguments[0])", key
);
Try this:
window.localStorage.getItem("BrowserHandoffStore");
Example here:
window.localStorage.setItem("test", false);
window.localStorage.getItem("test")
Output:
false
for who maybe still are looking for the solution:
you can use web driver executeScript
async function(localStorageFieldName){
await driver.executeScript(function(){
return localStorage.getItem(arguments[0])
},localStorageFieldName)
}
reference to executeScript : link

PasswordSignInAsync returning Success instead of RequiresVerification

I'm trying to set up Two Factor Authentication on our app. Updated a user in AspNetUsers table and set it's TwoFactorEnabled value to 1 for testing.
While debugging, signInManager.PasswordSignInAsync return just "success", not "requires verification".
This is the line
signInStatus = await signInManager.PasswordSignInAsync(viewModel.Email, viewModel.Password, true, shouldLockout: false);
(Similar questions are generally answered as first value should be name instead of email but I don't think it's the issue. Login works correctly, for example if password is wrong it returns failure.)
I added the line below to Startup.Auth.cs too
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(10));
I'm still able to work with what I have like this (though I don't want to)
if (signInStatus == SignInStatus.Success && user.TwoFactorEnabled == true)
{
//rest of code to be written
}
but this feels too makeshift of a solution and feels prone to many future errors. I'd prefer using Identity but I can't at the moment because of this problem.
It is obvious I'm doing something wrong or missing something but I don't know what. Thanks in advance.
I found my solution by copying the SignInManager code directly into mine and stepping through it, you can learn more about that here: https://stackoverflow.com/a/52357870/550975
SignInManager return RequiresVerification if :
dbo.ASpnetUsers has for user set to true TwoFactorEnabled and EmailConfirmed and user
email should be confirmed, email not be empty or null.

Check if user is logged in with Meteor

How can I determine layout depending on whether the user is logged in or not in Meteor?
I have tried
Router.map(function () {
this.configure({
layoutTemplate: Meteor.userId() ? "appLayout" : "startLayout",
});
});
I get the error
Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
It seems that Meteor.user() returns undefined if it's loading and null if it's logged out, same is true of Meteor.userId().
if(Meteor.userId(){
layoutTemplate: "appLayout";
}else{
layoutTemplate: "startLayout";
}
Did you try something like this ?
You can use this.userId, as error mentioned Meteor.user() you can use in functions, otherwise use Meteor.users.findOne({_id: this.userId}) if you need any data from user collection.
Also, your iron-router structure is deprecated, here are new docs

How to make sure a user can only see and access their own data in Yii

In Yii, is there a best way to make sure a user can only see and access their own data in Yii?
I thought an Admin should be able to see anything, but for now, I'll cross that bridge later.
Thanks
Look into scopes. Default scopes will be your friend:
http://www.yiiframework.com/doc/guide/1.1/en/database.ar#named-scopes
Because the defaultScopes array is inside of a function, you can also do conditional default scopes:
public function defaultScope()
{
$t=$this->getTableAlias(false,false);
if(Yii::app()->user->notAdmin()) {
return array(
'condition'=>"$t.<column_name> = :<columnName>",
'params'=>array(':<columnName>'=>Yii::app()->user->notAdmin),
);
}
else return array();
}
Edit: Note that this can get you in trouble down the road if you aren't careful. See this issue on the Yii site for more info.
There is no way Yii will do this for you, you'll do it on your own, but it's fairly straight forward.
You can consider scopes, or look into Relations and base them all on current user. For example, to get all posts by a user, you can do:
$posts = Post::model()->findAll(); //WRONG
$posts = Yii::app()->user->posts(); //RIGHT (Should define the relation in the User model)
Check out a solution which I wrote:
http://www.yiiframework.com/forum/index.php/topic/42735-restrict-users-to-only-editingdeleting-their-own-entries/page_gopid_237608#entry237608

Render template to variable in expressjs

Is there a way to render template to a variable instead to output?
res.render('list.ejs', {
posts: posts
});
something like this
var list = render('list.ejs', {
posts: posts
});
The easiest way to do that is to pass a callback to res.render, in your example:
res.render('list.ejs', {posts: posts}, function(err, list){
//
});
But if you want to render partial templates in order to include them in another template you definitely should have a look at view partials.
I am quite a newbie on express.js, anyway I am not sure you can access the rendered string that way, although if you look at express' "view.js" source on github (here) you see that it's accepting a callback as second argument, if that may help: you may access the rendered string there.
Otherwise, I think it's quite easy to patch the code to add a method returning the rendered string without sending it: on line #399 you have the very call that gives the string you are looking for.
This wasn't the question originally asked, but based on comments from the OP and others, it seems like the goal is to render a partial via json (jsonp), which is something I just had to do.
It's pretty easy:
app.get('/header', function (req, res)
{
res.render('partials/header', { session: req.session, layout: null }, function (err, output)
{
res.jsonp({ html: output });
});
});
Note: In my case, the header partial required the session, and my template library (express-hbs) needed layout: null to render the partial without using the default layout.
You can then call this from Javascript code in the client like any other JSONP endpoint.

Resources