asp.net-session https://www.e-learn.cn/tag/aspnet-session zh-hans Invalid Arguments error in Global.asax in mvc https://www.e-learn.cn/topic/3245708 <span>Invalid Arguments error in Global.asax in mvc</span> <span><span lang="" about="/user/226" typeof="schema:Person" property="schema:name" datatype="">泄露秘密</span></span> <span>2020-01-17 03:36:13</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I`m trying to follow the tutorial Securing Asp.net but when i try to put this line </p> <pre><code>GlobalConfiguration.Configuration.Filters.Add(new System.Web.Http.AuthorizeAttribute()); </code></pre> <p>it gives me a following error</p> <pre><code>The best overloaded method match for 'System.Web.Http.Filters.HttpFilterCollection.Add(System.Web.Http.Filters.IFilters)' has some invalid agruments </code></pre> <p>below is my Global.asax code</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using DatabaseService_WebAPI.App_Start; namespace DatabaseService_WebAPI { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { System.Data.Entity.Database.SetInitializer(new DatabaseService_WebAPI.Models.ProductContextInitializer()); System.Data.Entity.Database.SetInitializer(new DatabaseService_WebAPI.Models.LocalDBContextInitializer()); System.Data.Entity.Database.SetInitializer(new DatabaseService_WebAPI.Models.GCMClassContextInitializer()); System.Data.Entity.Database.SetInitializer(new DatabaseService_WebAPI.Models.ProductTypeContextInitializer()); GlobalConfiguration.Configuration.Filters.Add(new System.Web.Mvc.AuthorizeAttribute()); WebApiConfig.Configure(GlobalConfiguration.Configuration); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); } public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new System.Web.Mvc.AuthorizeAttribute()); filters.Add(new RequireHttpsAttribute()); } } } </code></pre> <p>I`m not an expert developer in mvc. so anyone can tell how to add filters?</p> <br /><h3>回答1:</h3><br /><p>Create this method in global.asax.cs:</p> <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters) { // add filters here filters.Add(new MyCustomFilter()); } </code></pre> <p>Then call it from the <code>Application_Start</code> method:</p> <pre><code>protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/13671445/invalid-arguments-error-in-global-asax-in-mvc</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/aspnet-mvc-4" hreflang="zh-hans">asp.net-mvc-4</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Thu, 16 Jan 2020 19:36:13 +0000 泄露秘密 3245708 at https://www.e-learn.cn Classic ASP to ASP.Net one-off session data copy https://www.e-learn.cn/topic/3202968 <span>Classic ASP to ASP.Net one-off session data copy</span> <span><span lang="" about="/user/24" typeof="schema:Person" property="schema:name" datatype="">Deadly</span></span> <span>2020-01-13 16:28:46</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We have an extensive classic ASP site, and we're looking to upgrade to ASP .Net (most probably the latest version). Obviously upgrading all the pages at once would be a leviathan task, so we're only looking to write new pages (and page rewrites) in ASP .Net at first.</p> <p>There are two obstacles to doing so:</p> <ol><li><p>I have no idea how to access classic ASP session data in ASP .Net. This would only have to be set up once, as it is never modified by any page other than the login page. I'd prefer to have to make minimal changes to the classic ASP login page, but that's only a small preference.</p></li> <li><p>The ASP and ASP .Net sessions would have to timeout at the same time, to keep the version difference seamless.</p></li> </ol><p>Could anyone offer any help, please?</p> <p>Thanks in advance.</p> <br /><h3>回答1:</h3><br /><p>We faced the same task (not fun). Since Asp.Net session and Asp session can't be shared, we used a combination of methods, each appropriate to the situation.</p> <ul><li>In some cases, we used cookies instead of session.</li> <li>In others, we set up automatically posting forms so that if a user's session information was set in a classic ASP page, after the session info was set, we redirected to an Asp.Net page that read in query string parameters and used those to set the same session variables for Asp.Net. Then once the Asp.Net page set the same variables, that page did a redirect to whatever page the original login page previously pointed to. The same worked in reverse.</li> </ul><p>So, in the second scenario, an example flow would have changed from:</p> <blockquote> <p>User tries to access some protected content page -&gt; redirected to login page -&gt; logs in -&gt; session info set based on login success -&gt; redirected back to content page.</p> </blockquote> <p>to </p> <blockquote> <p>User tries to access some protected content page -&gt; redirected to login page -&gt; logs in -&gt; session info set based on login success -&gt; redirected to a .net page, passing along login credentials, etc. -&gt; aspx page sets session info and then immediately redirects back to content page.</p> </blockquote> <p>We knew it was a hack, but it worked in the short-term until we could get the sites all converted.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>There might be a better way of doing this using newer IIS settings (must admit I've not kept up to date on what new goodies IIS7 can do). But you could do a XMLRequest from your ASP login page to a ASP.Net page. You could either pass through the settings you need in the Post data or have the .net page populate the session data itself if the logic is simple enough. The .net page would then return you a .net session id in the cookie, you need to set this in the ASP users cookie collection so that that user has both a .net and Classic ASP session cookie.</p> <p>That would do it.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>I implemented this a few years ago by using a database. </p> <p>Microsoft have a pretty good article on it, though it's a little old at this point.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/1526844/classic-asp-to-asp-net-one-off-session-data-copy</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/aspnet" hreflang="zh-hans">ASP.NET</a></div> <div class="field--item"><a href="/tag/asp-classic" hreflang="zh-hans">asp-classic</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Mon, 13 Jan 2020 08:28:46 +0000 Deadly 3202968 at https://www.e-learn.cn ASP.NET MVC 3 - Dealing with Session variables https://www.e-learn.cn/topic/3054350 <span>ASP.NET MVC 3 - Dealing with Session variables</span> <span><span lang="" about="/user/208" typeof="schema:Person" property="schema:name" datatype="">百般思念</span></span> <span>2020-01-02 03:16:09</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have an app which uses Form's Authentication and when the user log's in, I retrieve the user's actual name and assign that to a session variable, like so:</p> <pre><code>[HttpPost] public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { Session["Name"] = client.GetName(model.UserName); FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); return RedirectToAction("Index", "Home"); } } } </code></pre> <p>This is then displayed on my Index view, like so:</p> <pre><code>&lt;h3&gt;Welcome, @Session["Name"]&lt;/h3&gt; </code></pre> <p>So if my name was Bob, it would output "Welcome, Bob" on my view and this works fine. But once I navigate away from the page or close my browser and return a few minutes later, it seems as if these Session variables have been destroyed as it just outputs "Welcome, " but I'm still logged in so my session isnt destroyed? I've set the session to be destroyed after 60 minutes in my web.config:</p> <pre><code>&lt;sessionState regenerateExpiredSessionId="true" timeout="60" /&gt; </code></pre> <h2>Edit</h2> <p>This only happens when I check my "Remember Me" box when logging in, as I guess this keeps a cookie client side so when I re-open my browser Im still logged in but a new session ID is created as I did a <code>Response.Write(Session.SessionID)</code> on my Index page and the ID before I closed my browser was different to the one when I re-opened it. If I don't check my "Remember Me" box then I'm forced to login again upon re-opening my browser</p> <br /><h3>回答1:</h3><br /><p>I had the same problem with my session variables. If the remember me option was selected at the logon it would bypass my code to set the session variable I needed the next time the user would go to the site.</p> <p>I was able to solve my issue by repopulating the session variable if the IsAuthenticated was true.</p> <p></p> <pre><code>protected void Session_Start(object sender, EventArgs e) { if (User.Identity.IsAuthenticated) { Session["Name"] = client.GetName(User.Identity.Name); } } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>Instead of adding the name to a session variable, just change the following</p> <pre><code>FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); </code></pre> <p>to</p> <pre><code>FormsAuthentication.SetAuthCookie(client.GetName(model.UserName), model.RememberMe); </code></pre> <p>You can then just use the User.Identity.Name instead of the @Session["Name"].</p> <br /><br /><br /><h3>回答3:</h3><br /><p>The issue you have is with the line</p> <pre><code>FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); </code></pre> <p>This is a cookie and last longer than sessions (depending on how long you set the forms timeout)</p> <p>If all you need is to just display the username, you can use and just remove the session altogether</p> <pre><code>&lt;h3&gt;Welcome, @User.Identity.Name&lt;/h3&gt; </code></pre> <br /><br /><br /><h3>回答4:</h3><br /><pre><code>FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); </code></pre> <p>this code should work fine and you should be able to see <code>"Welcome USERNAME"</code>, try to see that whether IE settings like <code>tools--&gt;internet options--&gt;General</code> tab <code>delete my browsing history</code> is checked or not. (on the same tab is you click on delete button you will see its clearing cookies also so that might be issue).</p> <p>Cookies values will be retained if you close browser but not session(inproc) variables.</p> <br /><br /><br /><h3>回答5:</h3><br /><p>Maybe first check to ensure that a new session isn't started somehow. Place a breakpoint in the <code>Session_Start</code> in the <code>global.asax.cs</code> file:</p> <pre><code>protected void Session_Start(object sender, EventArgs e) { var sessionId = Session.SessionID; // break here } </code></pre> <p>It might seem silly but there are a couple of things that could actually cause a new session. Eliminating those will get you closer to a solution.</p> <p>Closing your browser and opening it up again will probably cause a new session. Changes to the folder structure within your site and changes to the web.config will cause a new session (application pool will be recycled).</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/10123143/asp-net-mvc-3-dealing-with-session-variables</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/aspnet-mvc-3" hreflang="zh-hans">asp.net-mvc-3</a></div> <div class="field--item"><a href="/tag/forms-authentication" hreflang="zh-hans">forms-authentication</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Wed, 01 Jan 2020 19:16:09 +0000 百般思念 3054350 at https://www.e-learn.cn Windows Azure Cache Preview https://www.e-learn.cn/topic/2755376 <span>Windows Azure Cache Preview</span> <span><span lang="" about="/user/17" typeof="schema:Person" property="schema:name" datatype="">…衆ロ難τιáo~</span></span> <span>2019-12-22 08:08:06</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm having some trouble using Windows Azure Cache Preview.</p> <p>I've add the Nuget Package here: http://nuget.org/packages/Microsoft.WindowsAzure.Caching and have configured my role for storing the ASP.NET sessions state as per the info on windowsazure.com</p> <p>Problem is, I get <code>No connection could be made because the target machine actively refused it 127.255.0.0:20004</code> when debugging. The dev IP used by Azure is 12.7.0.0.1:81</p> <p>I'm not sure why, even the sample <code>Windows Azure Caching (Preview) Session State and Output Caching Sample</code> does the exact same thing.</p> <p><strong>Update: error from log:</strong></p> <pre><code>w3wp.exe Error: 0 : ERROR: &lt;SimpleSendReceiveModule&gt; b4551065-941b-4bdb-9487-57d9207af308:Request - 1, result - Status=ChannelOpenFailed[System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 127.255.0.0:20004 at Microsoft.ApplicationServer.Caching.AsyncResultNoResult.EndInvoke() at Microsoft.ApplicationServer.Caching.TcpClientChannel.ConnectionCallback(IAsyncResult result)] for end point [net.tcp://127.255.0.0:20004] </code></pre> <p>Also, more testing shows it is just not for session state storage, but all cache related tasks.</p> <br /><h3>回答1:</h3><br /><p>found the answer , in the webrole or workerrole properties, set the number of instances to minimum 2, this is the issue for me. got it resolved after 8 hours of debugging </p> <br /><br /><br /><h3>回答2:</h3><br /><p>I haven't seen this error personally so I'm taking a couple stabs in the dark...</p> <p>Did you enable the caching preview in the role properties tab? That step sets up the "server" side of the caching solution.</p> <p>You also need to make very sure that the names in the various configurations are consistent or the caching client won't be able to find the service. You should find one of these in the web.config in the dataCacheClient section. SPecifically the identifier attribute.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>For others that have the same problem, there are two other possible solutions in case the resolution proposed by Sundara Prabu does not work:</p> <ol><li>simply reboot your computer, as suggested in this thread on MSDN forums;</li> <li>in the Regional Settings of Windows change the Long Time format to <code>HH:mm:ss</code>. As I discovered myself by reading this SO answer, the cache emulator calls logman.exe for logging purposes and in particular, it uses the <code>cnf</code> parameter, that requires a duration in the format <code>HH:mm:ss</code>. The cache emulator instead formats this duration using the Long Time format found in the Regional Settings -- in my case, using Italian settings under Windows 8 the format used was <code>HH.mm.ss</code>, thus causing the problem described in the question.</li> </ol><br /><br /><p>来源:<code>https://stackoverflow.com/questions/11519783/windows-azure-cache-preview</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/aspnet" hreflang="zh-hans">ASP.NET</a></div> <div class="field--item"><a href="/tag/caching" hreflang="zh-hans">caching</a></div> <div class="field--item"><a href="/tag/azure" hreflang="zh-hans">azure</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Sun, 22 Dec 2019 00:08:06 +0000 …衆ロ難τιáo~ 2755376 at https://www.e-learn.cn Set / update expiration on aspxauth and asp.net_sessionid cookies https://www.e-learn.cn/topic/2734708 <span>Set / update expiration on aspxauth and asp.net_sessionid cookies</span> <span><span lang="" about="/user/195" typeof="schema:Person" property="schema:name" datatype="">若如初见.</span></span> <span>2019-12-21 22:17:25</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am wondering if there is a way you can setup your .NET application to set and update the expiration time of the aspxauth and asp.net_sessionid cookies in the browser? </p> <p>From what I see, the cookies' expiration dates are something like 1/1/0001 telling the browser to keep them until the browser closes (I've observed this using Chrome). I'd like to set an explicit time, but, I will need to update that time on every request.</p> <p>I am attempting to do this with some code like : </p> <pre><code>var timeoutMins = Session.Timeout; if (Response.Cookies.Count &gt; 0) { foreach (string s in Response.Cookies.AllKeys) { if (s == FormsAuthentication.FormsCookieName || s.ToLower() == "asp.net_sessionid") { Response.Cookies[s].Expires = DateTime.Now.AddMinutes(timeoutMins); } } } </code></pre> <p>I tried doing this in the global.asax End_Request event, although this doesn't seem to be a good place since it fires several times per page and you dont have access to the sessionstate timeout; further it only triggers on login and logout, so basically I can set it once but I can never update it. This causes my users to be logged out 15 minutes after login even if they have been active.</p> <p>It seems like there would be some setting somewhere to tell .net to handle this? I know this is a strange request but it is a security requirement on this project so I'm trying to make it work!</p> <br /><h3>回答1:</h3><br /><p>It looks like not many people are trying to do what I'm doing, but for the record, I added code to the application end request to find the cookies in the request and recreate them in the response with the appropriate expiration time : </p> <pre><code>var timeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["myTimeoutConfigSetting"]); foreach (var cookey in Request.Cookies.AllKeys) { if (cookey == FormsAuthentication.FormsCookieName || cookey.ToLower() == "asp.net_sessionid") { var reqCookie = Request.Cookies[cookey]; if (reqCookie != null) { HttpCookie respCookie = new HttpCookie(reqCookie.Name, reqCookie.Value); respCookie.Expires = DateTime.Now.AddMinutes(timeout); Response.Cookies.Set(respCookie); } } } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>Here is a nice way to do it </p> <p>http://www.andreas-kraus.net/blog/increase-aspnet-authentication-membership-cookie-timeout/</p> <p>and this one http://forums.asp.net/p/1158239/1920541.aspx#1920541</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/10439483/set-update-expiration-on-aspxauth-and-asp-net-sessionid-cookies</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/net" hreflang="zh-hans">.net</a></div> <div class="field--item"><a href="/tag/cookies" hreflang="zh-hans">cookies</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> <div class="field--item"><a href="/tag/aspxauth" hreflang="zh-hans">.aspxauth</a></div> </div> </div> Sat, 21 Dec 2019 14:17:25 +0000 若如初见. 2734708 at https://www.e-learn.cn How maintain session beetween two Url in asp. Net https://www.e-learn.cn/topic/2482540 <span>How maintain session beetween two Url in asp. Net</span> <span><span lang="" about="/user/153" typeof="schema:Person" property="schema:name" datatype="">风流意气都作罢</span></span> <span>2019-12-13 17:22:21</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have two URl's . If I open first url it will allow us authentication. Second URL will open web content as XML data. I need to read that data... But when I excute first URL its working fine Authentication is SUCCESS, But immediately I try to open second URL its saying Authentication failed . How to maintain session from first URL to second URL... </p> <p>My Code : </p> <pre><code>string url1 = "http://172.xx.xx.xx:xxxx/cms?login&amp;username=santhu&amp;password=welcom0e"; string url = "http://172.xx.xx.xx:xxxx//cms?status=ProcessStatus"; string result = null; string result1 = null; try { WebClient client = new WebClient(); result = client.DownloadString(url1); TextBox1.Text = result.ToString(); result1 = client.DownloadString(url); TextBox2.Text = result1.ToString(); } catch (Exception ex) { } </code></pre> <br /><h3>回答1:</h3><br /><pre><code>private class CookieAwareWebClient : WebClient { public CookieAwareWebClient(): this(new CookieContainer()) { } public CookieAwareWebClient(CookieContainer c) { this.CookieContainer = c; } public CookieContainer CookieContainer { get; set; } protected override WebRequest GetWebRequest(Uri address) { WebRequest request = base.GetWebRequest(address); if (request is HttpWebRequest) { (request as HttpWebRequest).CookieContainer = this.CookieContainer; } return request; } } </code></pre> <p>Otherwise you can solve the problem by adding the values manually by using Firebug for cookies :)</p> <pre><code>webClient.Headers.Add("Cookie", "PHPSESSID=xxxxxxx; mosesuser=xxxxxxx; "); </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>You will need to remember the "Set-Cookie" response header from the first request and send it in your second request.</p> <p>Basically, after the first request (probably after DownloadString() you would need to find the header in <code>client.ResponseHeaders</code>, and then you would need to add it to <code>client.Headers</code> somehow. </p> <p>EDIT: Seems like the above isn't possible, but you can modify the underlying WebRequest instance, see this question: How can I get the WebClient to use Cookies?</p> <p>or this: http://couldbedone.blogspot.com/2007/08/webclient-handling-cookies.html</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/6451575/how-maintain-session-beetween-two-url-in-asp-net</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Fri, 13 Dec 2019 09:22:21 +0000 风流意气都作罢 2482540 at https://www.e-learn.cn DataServiceRequestException with TableStorageSessionStateProvider https://www.e-learn.cn/topic/2447760 <span>DataServiceRequestException with TableStorageSessionStateProvider</span> <span><span lang="" about="/user/205" typeof="schema:Person" property="schema:name" datatype="">耗尽温柔</span></span> <span>2019-12-13 05:47:19</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm trying to use the TableStorageSessionStateProvider from the Azure training kit. I can use the example without problems but when I use it in my web app, I get this exception:</p> <pre><code>System.Data.Services.Client.DataServiceRequestException occurred Message=An error occurred while processing this request. Source=Microsoft.WindowsAzure.StorageClient StackTrace: at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait() at Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider.&lt;&gt;c__DisplayClass5.&lt;ResetItemTimeout&gt;b__4() InnerException: System.Data.Services.Client.DataServiceClientException Message=&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt; &lt;error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"&gt; &lt;code&gt;UpdateConditionNotSatisfied&lt;/code&gt; &lt;message xml:lang="en-US"&gt;The update condition specified in the request was not satisfied. RequestId:c552d552-ba1c-4920-84fc-e716705b58b9 Time:2011-02-17T12:43:38.5650557Z&lt;/message&gt; &lt;/error&gt; Source=System.Data.Services.Client StatusCode=412 StackTrace: at System.Data.Services.Client.DataServiceContext.SaveResult.&lt;HandleBatchResponse&gt;d__1e.MoveNext() InnerException: </code></pre> <p>I've tried this, but no luck so far.I've also seen null reference exceptions happening, so I guess that the TableStorageSessionStateProvider it's not behaving like the InProc one, so maybe I have to check how sessions are being used in the application. But, what could be the problem ?</p> <p>EDIT: Well, I've find out that the example in the Azure training kit also fails if you only use the TableStorageSessionStateProvider with the same exception. You just have to comment the other providers:</p> <p> </p> <pre><code>&lt;authentication mode="Forms"&gt; &lt;forms loginUrl="~/Account/Login.aspx" timeout="2880" /&gt; &lt;/authentication&gt; &lt;!-- Membership Provider Configuration --&gt; &lt;!--&lt;membership defaultProvider="TableStorageMembershipProvider" userIsOnlineTimeWindow="20"&gt; &lt;providers&gt; &lt;clear /&gt; &lt;add name="TableStorageMembershipProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider" description="Membership provider using table storage" applicationName="AzureStore" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" requiresUniqueEmail="true" passwordFormat="Hashed" /&gt; &lt;/providers&gt; &lt;/membership&gt; &lt;profile&gt; &lt;providers&gt; &lt;clear /&gt; &lt;add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /&gt; &lt;/providers&gt; &lt;/profile&gt; --&gt;&lt;!-- RoleManager Provider Configuration --&gt;&lt;!-- &lt;roleManager enabled="true" defaultProvider="TableStorageRoleProvider" cacheRolesInCookie="true" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All"&gt; &lt;providers&gt; &lt;clear /&gt; &lt;add name="TableStorageRoleProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageRoleProvider" description="Role provider using table storage" applicationName="AzureStore" /&gt; &lt;/providers&gt; &lt;/roleManager&gt;--&gt; &lt;!-- SessionState Provider Configuration --&gt; &lt;sessionState mode="Custom" customProvider="TableStorageSessionStateProvider"&gt; &lt;providers&gt; &lt;clear /&gt; &lt;add name="TableStorageSessionStateProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider" applicationName="AzureStore" /&gt; &lt;/providers&gt; &lt;/sessionState&gt; &lt;machineKey decryption="AES" decryptionKey="F7FA540B4DFD82E5BB196B95D15FF81F5B973B5514F973D2A46B4C52224A3ABC" validation="SHA1" validationKey="5B973B5514F973D2A46B4C52224A3ABC90378EFA9DE62168764FF0DCE537184F0535D5D9AD66DEDC5B973B5514F973D2A46B4C52224A3ABC90378EFA97DC1ABF" /&gt; </code></pre> <p></p> <br /><h3>回答1:</h3><br /><p>If you want to know why you're getting this error with the <code>TableStorageSessionProvider</code> see my answer to this question. If you want to know about the using the SQL session provider in Azure see the answer to this question.</p> <p>If you need to use something today, you're only real choice is to use the SQL session provider even though it's not supported. Once AppFabric Caching is out of CTP it will be the way to go.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/5029293/dataservicerequestexception-with-tablestoragesessionstateprovider</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/session" hreflang="zh-hans">session</a></div> <div class="field--item"><a href="/tag/azure" hreflang="zh-hans">azure</a></div> <div class="field--item"><a href="/tag/azure-storage" hreflang="zh-hans">azure-storage</a></div> <div class="field--item"><a href="/tag/azure-web-roles" hreflang="zh-hans">azure-web-roles</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Thu, 12 Dec 2019 21:47:19 +0000 耗尽温柔 2447760 at https://www.e-learn.cn Does ASP .NET Session reset after login? https://www.e-learn.cn/topic/2205711 <span>Does ASP .NET Session reset after login?</span> <span><span lang="" about="/user/189" typeof="schema:Person" property="schema:name" datatype="">怎甘沉沦</span></span> <span>2019-12-11 05:40:00</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p><strong>EDIT</strong></p> <p>This problem seems to have strangely disappeared. There must've been something funky with my environment. I'm voting to close this question.</p> <hr /><p>When a user logs in, I inflate the session with a bunch of data from the Login page code-behind. Then I redirect the user to a different page in the application. I also have some session recovery logic which re-inflates the session based on the auth ticket when the user's session expires. </p> <p>What seems to be happening is that I inflate the user's session with a bunch of data from the login page, then redirect them, and the request for the page to which I redirect them doesn't seem to have the session, so the application has to re-inflate it. I don't understand this - I've looked at the cookie and the session ID is not changing, and I am not resetting the session data anywhere in the code. Is this an ASP .NET 'feauture'? I'm using ASP .NET 4.0.</p> <p><strong>Edit:</strong></p> <p>To clarify: The session is inflated during the login request (on the click even of the login button). During the next request, it doesn't appear the session is populated any longer, so I end up having to re-inflate the session. Any requests that user makes after that, the session seems to "stick" and I have the properly inflated session for subsequent requests.</p> <br /><h3>回答1:</h3><br /><p>To answer your question <code>SessionState</code> data is independent of login/logout.</p> <p>There are several reasons why data might "disappear" from <code>SessionState</code>.</p> <ul><li>If you are using <code>InProc</code> <code>SessionState</code> on a web farm, the user may have a subsequent request be served by a different machine in the farm. </li> <li><code>SessionState</code> can clear if it gets too full (like a cache). </li> <li>If you are using a custom <code>SessionStateStoreProvider</code>, it may not be saving/retrieving the <code>SessionState</code> properly.</li> </ul><br /><br /><p>来源:<code>https://stackoverflow.com/questions/6293159/does-asp-net-session-reset-after-login</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/aspnet" hreflang="zh-hans">ASP.NET</a></div> <div class="field--item"><a href="/tag/session" hreflang="zh-hans">session</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Tue, 10 Dec 2019 21:40:00 +0000 怎甘沉沦 2205711 at https://www.e-learn.cn Storing values in asp.net session using jquery https://www.e-learn.cn/topic/2156010 <span>Storing values in asp.net session using jquery</span> <span><span lang="" about="/user/18" typeof="schema:Person" property="schema:name" datatype="">非 Y 不嫁゛</span></span> <span>2019-12-10 23:54:12</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>How to store values in the session using jquery. I am using the following code </p> <pre><code>var Link = '&lt;%=Session["Link"]%&gt;'; </code></pre> <p>to get data from session. How to do the reverse process.</p> <p>Problem:</p> <pre><code> I need this in my master page. so i cant use .ajax{}. </code></pre> <p>Geetha</p> <br /><h3>回答1:</h3><br /><p>You will probably need to set up an HTTP handler or something similar that will accept requests and store things in the Session. Visual studio has this somewhere in the "Add" menus in the solution view. (If you're using ASP.NET MVC, you just set up another action instead of a generic handler.)</p> <p>Since those values will may have different types (int, string, etc.) <em>and</em> since you don't want malicious users poking into any session key they see fit, you will probably want to set up a branch to determine what to do with each key. Something like this (inside the handler that you created):</p> <pre><code>string key = context.Request.QueryString["key"].ToString(); string val = context.Request.QueryString["val"].ToString(); if(key == "AshDiffuserID"){ int ash_diffuser_id = Convert.ToInt32(val); Session["AshDiffuserID"] = ash_diffuser_id; } else if(key == "PesterchumHandle") { string handle = val; Session["PesterchumHandle"] = handle; } else // etc... </code></pre> <p>After that, you'll need to set up a post HTTP request through jquery that puts whatever values you need in those "key" and "val" fields.</p> <pre><code>$.post( 'url/to/your/handler.ashx', {key: "PesterchumHandle", val: "carcinoGenetecist"} ); </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>I wasted my whole day to sort this problem while this is just a quick fix. During PageMethod call, session id is not being passed with request URL, so new session_start event is getting fired. We just need to set exact request path before calling a pagemethod, so that new session start event can not be fired.</p> <pre><code>if ('&lt;%= HttpContext.Current.Session.IsCookieless %&gt;==True') { //need to pass session id in request path PageMethods.set_path('&lt;%= System.Web.Configuration.WebConfigurationManager.AppSettings("WebRoot") %&gt;(S(&lt;%=Session.SessionID%&gt;))/secure/PageName.aspx'); } PageMethods.PageMethodName(param1,param2, CallSuccess, CallFailed); </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>You will need to do an ajax post to the server via jquery.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/2332082/storing-values-in-asp-net-session-using-jquery</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/jquery" hreflang="zh-hans">jquery</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Tue, 10 Dec 2019 15:54:12 +0000 非 Y 不嫁゛ 2156010 at https://www.e-learn.cn Windows Azure Cache Preview https://www.e-learn.cn/topic/1708865 <span>Windows Azure Cache Preview</span> <span><span lang="" about="/user/9" typeof="schema:Person" property="schema:name" datatype="">爷,独闯天下</span></span> <span>2019-12-05 12:37:55</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="alert alert-danger" role="alert"> <p>I'm having some trouble using Windows Azure Cache Preview.</p> <p>I've add the Nuget Package here: <a href="http://nuget.org/packages/Microsoft.WindowsAzure.Caching" rel="nofollow">http://nuget.org/packages/Microsoft.WindowsAzure.Caching</a> and have configured my role for storing the ASP.NET sessions state as per the info on windowsazure.com</p> <p>Problem is, I get <code>No connection could be made because the target machine actively refused it 127.255.0.0:20004</code> when debugging. The dev IP used by Azure is 12.7.0.0.1:81</p> <p>I'm not sure why, even the sample <code>Windows Azure Caching (Preview) Session State and Output Caching Sample</code> does the exact same thing.</p> <p><strong>Update: error from log:</strong></p> <pre><code>w3wp.exe Error: 0 : ERROR: &lt;SimpleSendReceiveModule&gt; b4551065-941b-4bdb-9487-57d9207af308:Request - 1, result - Status=ChannelOpenFailed[System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 127.255.0.0:20004 at Microsoft.ApplicationServer.Caching.AsyncResultNoResult.EndInvoke() at Microsoft.ApplicationServer.Caching.TcpClientChannel.ConnectionCallback(IAsyncResult result)] for end point [net.tcp://127.255.0.0:20004] </code></pre> <p>Also, more testing shows it is just not for session state storage, but all cache related tasks.</p> </div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>found the answer , in the webrole or workerrole properties, set the number of instances to minimum 2, this is the issue for me. got it resolved after 8 hours of debugging </p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>I haven't seen this error personally so I'm taking a couple stabs in the dark...</p> <p>Did you enable the caching preview in the role properties tab? That step sets up the "server" side of the caching solution.</p> <p>You also need to make very sure that the names in the various configurations are consistent or the caching client won't be able to find the service. You should find one of these in the web.config in the dataCacheClient section. SPecifically the identifier attribute.</p> </div></div><div class="panel panel-info"><div class="panel-heading">edymtt</div><div class="panel-body"> <p>For others that have the same problem, there are two other possible solutions in case the resolution proposed by Sundara Prabu does not work:</p> <ol><li>simply reboot your computer, as suggested in this <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/fb4b3505-aca9-44f3-843b-dc98de83a9d9/" rel="nofollow">thread on MSDN forums</a>;</li> <li>in the Regional Settings of Windows change the Long Time format to <code>HH:mm:ss</code>. As I discovered myself by reading <a href="https://stackoverflow.com/a/15407741/753737" rel="nofollow">this SO answer</a>, the cache emulator calls <a href="http://technet.microsoft.com/en-us/library/bb490956.aspx" rel="nofollow"><code>logman.exe</code></a> for logging purposes and in particular, it uses the <code>cnf</code> parameter, that requires a duration in the format <code>HH:mm:ss</code>. The cache emulator instead formats this duration using the Long Time format found in the Regional Settings -- in my case, using Italian settings under Windows 8 the format used was <code>HH.mm.ss</code>, thus causing the problem described in the question.</li> </ol></div></div><div class="alert alert-warning" role="alert"><p>来源:<code>https://stackoverflow.com/questions/11519783/windows-azure-cache-preview</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/aspnet" hreflang="zh-hans">ASP.NET</a></div> <div class="field--item"><a href="/tag/caching" hreflang="zh-hans">caching</a></div> <div class="field--item"><a href="/tag/azure" hreflang="zh-hans">azure</a></div> <div class="field--item"><a href="/tag/aspnet-session" hreflang="zh-hans">asp.net-session</a></div> </div> </div> Thu, 05 Dec 2019 04:37:55 +0000 爷,独闯天下 1708865 at https://www.e-learn.cn