I have one scenario, where i have to send data between asp.net webpage(aspx)or codebehind data to my MVC2 Controller Action method. It is conversion project where asp.net and mvc will run side by side and need to share data between pages..so any body have an idea or one sample to achieve this..we are using session but when it redirect to mvc action method the session becomes null(as HttpContext of webpage is different from MVC controller). As we have logic there in codebehind based on that logic we are sending data form aspx.cs page to mvc controller action method.

In my ASP.NET MVC 5 application, I'm performing a GET request on a method inside a controller that needs to read a value stored in session. To avoid session state locking issue, I've set SessionStateBehavior to ReadOnly on the class level.

 [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class TestController: Controller
    {
         var test = Session["KEY"];
...

However, very occasionally, I need to overwrite the Session variable to something else inside that same method. ASP.NET MVC does not allow me to do this with SessionStateBehavior set to ReadOnly. I can't set it to Required because then I run into the issue of session state locking issue again, preventing concurrent AJAX requests.

What's a good solution for this?

Edit: We're using SQL server for session state management.

First of all I have already look at the similar solution to the following ones:

ASP.NET MVC : Handle Session Expire Using Custom Attribute

Redirect to specific page after session expires (MVC4)

But I need a smart solution regarding to this problem by just typing a code on Global.asax etc. and not requiring an extra implementation on every Cntroller. Is it possible? If not, what is the best approach for redirecting to login page after session is timeout in ASP.NET MVC?

I have got a basic doubt about ASP.NET MVC. Here is what I got in my mind about ASP.NET MVC:

1) .NET : Have many generic libraries and features can be combined user code.

2) MVC : Framework where programing done in model-view-controller method of three available in .net

3) ASP : A client and server side scripting language used to create UI and have other server objects like section.

4) ASP.NET: Built many frames of ASP like toolkit to use asp more easily.

So in ASP.NET MVC:

a. ASP Using Only server objects like session, Request etc

b. Not Using ASP.NET in MVC 5 instead there is only razor for UI.

c. .NET does the generic code generation in development.

Am I right about it. If not mention point number[1)] or name[a.] and please explain me why I am wrong.

Hoping for best answers because I didn't find clear answers for these type of questions on web.

In my ASP.NET MVC 5 application, I'm performing a GET request on a method inside a controller that needs to read a value stored in session. To avoid session state locking issue, I've set SessionStateBehavior to ReadOnly on the class level.

 [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class TestController: Controller
    {
         var test = Session["KEY"];
...

However, very occasionally, I need to overwrite the Session variable to something else inside that same method. ASP.NET MVC does not allow me to do this with SessionStateBehavior set to ReadOnly. I can't set it to Required because then I run into the issue of session state locking issue again, preventing concurrent AJAX requests.

What's a good solution for this?

I have created the internet application ASP.NET MVC Using RAZOR.

I have written in Index.cshtml as:

@Session["my"]="Hello".

and I have written in AboutUs.cshtml as:

@Session["my"]

Still now I can't get the value from AboutUs.cshtml . Instead of it in Index.cshtml it shows:

="Hello"

I am having an asp.NET MVC application in which there are many bundles defined. Right now the bundles are served as it is without checking whether user session exists or not using bundle URL. I want to secure few of these static resources such as bundles or CSS or any other JS so that they are only served when user session is there even if with a direct URL access.

Is this kind of thing possible?

I am working on application whose details are as follows:

  1. Its 3 tier architecture. Web Tier (ASP.Net MVC) -- Service Tier (ASP.Net WebApi 2) -- Database Tier(MS SQL 2014).
  2. Application will also have native mobile apps as clients which will consume Service tier.
  3. Service Tier (Web API) uses individual username/password in conjunction with OAuth for authentication and authorization.
  4. User details are stored using ASP. Net Identity system. ASP. Net Identity database tables are in same database as that of application database.
  5. There will be no direct calls from clients i.e. web or mobile apps to database and every request has to go via service layer.
  6. Users of web client and mobile apps will be authenticated against asp.net identity database which is part of application database.

I have partially implemented above architecture however facing one challenge i.e. once user is authenticated, OAuth token will be issued from service layer which will be valid for one day. But how and where should I securely store this token in Web Client (ASP.Net MVC app) so that user needs to login only once in day and not for every single request that it makes. One option I can think of is once user is authenticated and token is received in web client then store it in in-memory session storage and use it for further requests. However down side of this is, it will reduce scalability of application and will require sticky sessions in load balanced environment. Is there any better way I can handle this situation? Also want to validate above architecture if its correct architecture?

I have recently managed to create a user management application that utilized a token based authentication via web api. This is where I found it from http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/

I was wondering if it was possible to create user accounts in that User Management application and then use that account from another application that I will load up onto the same environment?

Hopefully this sketch will help to explain. enter image description here

I also have a few questions. If I receive a token, I know that on my user management application, it will be valid for however long I set it. How will my other application know that I have been authenticated? Does this mean that I will have to verify that token with each web api call that I make in Application A?

Also, does ASP MVC use sessions? I am currently using Codeigniter and heavily rely on sessions to carry my users data such as logged in status. How does ASP MVC not allow a user to use the back button once they have logged out?

Sorry, I haven't seen much of what I asked online and so I'm hoping someone could help me with this.

I have recently managed to create a user management application that utilized a token based authentication via web api. This is where I found it from http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/

I was wondering if it was possible to create user accounts in that User Management application and then use that account from another application that I will load up onto the same environment?

Hopefully this sketch will help to explain. enter image description here

I also have a few questions. If I receive a token, I know that on my user management application, it will be valid for however long I set it. How will my other application know that I have been authenticated? Does this mean that I will have to verify that token with each web api call that I make in Application A?

Also, does ASP MVC use sessions? I am currently using Codeigniter and heavily rely on sessions to carry my users data such as logged in status. How does ASP MVC not allow a user to use the back button once they have logged out?

Sorry, I haven't seen much of what I asked online and so I'm hoping someone could help me with this.

I am very new to ASP.Net, Razor and MVC.

How i can declare and access a global variable across all the pages in my MVC application ? Sometimes, this variable will be setting its value from java scripts as well.

I tried with Session and Application objects but no use at all.

Any Help ? I saw other posts here but it seems not suitable.

please help.