Developer forum

Forum » Templates » Code in Master.cshtml Razor file affects /Admin

Code in Master.cshtml Razor file affects /Admin

Dmitrij Jazel
Reply

Hi guys,

In my rescent example I tryed to run here, was HttpContext.Current.Session.Abandon() method I wanted to run in Master.cshtml in particular case.

By default if no url parameter present, it must run this.

 

Long story short, when I am requesting /Admin of this site, because I am not using a url parameter, this line gets executed!?

I mean that my session is getting Abondont, not sure if that is actually if that line executed, or what is the reason that /Admin just keeps logging off automatically (right after login) and brings me back to login screen.

As soon as I remove this line:HttpContext.Current.Session.Abandon()

/Admin works as it should.

 

My question:

I saw before that Styles are influencing /Admin in certain cases.

But why in the world, would /Master or any other html/cshtml files have to have a way to influence /Admin? I mean /Admin has another

Thoughts, comments, explonation?

/Dmitrij


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

When you run a list of paragraphs, Dynamicweb also makes a pageview instance and executes it - for analysis purpose.

You can add a conditional to your abondon call:

if(Dynamicweb.ExecutingContext.IsFrontEnd()){}

Votes for this answer: 1
 
Nicolai Høeg Pedersen
Reply

By the way, it sounds like a VERY bad idea to run Abandon in the frontend. Why would you ever want to do that? It triggers a lot of stuff to be executed both in IIS and DW.

 
Dmitrij Jazel
Reply

Hi Nicolai,

it sounds like a VERY bad idea to run Abandon in the frontend.

Totally agree, but ref my other post you replyed lately, I had to use it as very last option. It is not yet in final implementation, and I don't think it will make it there.

Will try putting it into Page.loaded event. And will try running things I need to run from there.

 

But the reason why I wrote it here, and asked the question, was because I found it weared that stuff that sometimes people has to use, somehow can affect master.

What if there is no other way arround an issue, and you just have to use some "not recomended" code in Master front-end. Than Admin is bound to do funny stuff just because of templates, and only templates.

I understand that if you are in front-end, and you actually run the code you need. That drops the sessions - this will evenedably affect the Admin and other things.

But when you just want to open Admin? And nothing else.

It should be as stable as possible, and as reliable as possible.

 

It's just a thought, but thanks for clearing this one out. atleast now I know that, and there is one more reason to avoid "not recomended" code in front-end at all.

/Dmitrij

 
Nicolai Høeg Pedersen
Reply

But why do you need to abondon session?

 
Dmitrij Jazel
Reply

This is a part of something that Lars (from DW) suggested when changing country / currency.

This is the code so far, and I will use it in the PageLoad event as you seen earlyer.

if(must_reddirect){
// change site language if must reddirect
    HttpContext.Current.Session.Abandon(); 
    HttpContext.Current.Response.Redirect(reddirectTo); // this reddirects to url - default "Frontpage"
}else{
    // either you came to the right site from the start, or you where reddirected by above code - you ended up on the right language.
    // Now you need to change the currency.
    Dynamicweb.eCommerce.Common.Context.CurrencySetByCustomer = true;
    Dynamicweb.eCommerce.Common.Context.Currency = new Dynamicweb.eCommerce.International.Currency(currencyCode);
}

 

 

 

You must be logged in to post in the forum