asp.net-mvc – 为什么Asp.net MVC4不能使用SQL Server会话状态
发布时间:2020-12-16 06:48:03 所属栏目:asp.Net 来源:网络整理
导读:ALL,这是我在 Asp.net MVC4应用程序中的Web配置.我发现如果我设置cookieless,一切都很顺利.但如果我不想使用cookie.然后应用程序无法工作.当我调试应用程序时,我发现控制器无法从视图接收任何请求.我认为这是因为在无cookie模式下,Something会被添加到url之
ALL,这是我在
Asp.net MVC4应用程序中的Web配置.我发现如果我设置cookieless,一切都很顺利.但如果我不想使用cookie.然后应用程序无法工作.当我调试应用程序时,我发现控制器无法从视图接收任何请求.我认为这是因为在无cookie模式下,Something会被添加到url之前.比如http:// localhost:8119 /(S(3cicpjpagvpunr5he5fnfrj1))/.
<configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,System.Web.WebPages.Razor,Version=2.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35"> <section name="webAssets" type="Telerik.Web.Mvc.Configuration.WebAssetConfigurationSection,Telerik.Web.Mvc" requirePermission="false" /> <!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=4.4.0.0,PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <connectionStrings> <add name="..." connectionString="..." providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="true" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <customErrors mode="Off" /> <httpRuntime executionTimeout="14400" maxRequestLength="716800" /> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication> <pages> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> <add namespace="Telerik.Web.Mvc.UI" /> </namespaces> </pages> <profile defaultProvider="DefaultProfileProvider"> <providers> <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider,System.Web.Providers,Version=1.0.0.0,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> </providers> </profile> <membership defaultProvider="DefaultMembershipProvider"> <providers> <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <roleManager defaultProvider="DefaultRoleProvider"> <providers> <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> </providers> </roleManager> <!-- <sessionState mode="InProc" timeout="30" customProvider="DefaultSessionProvider"> <providers> <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> </providers> </sessionState> --> <sessionState mode="SQLServer" cookieless="true" sqlConnectionString="data source=xxxx; User ID=xxxx; password=xxxx" timeout="300" sqlCommandTimeout="10" /> <httpHandlers> <add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler,Telerik.Web.Mvc" /> </httpHandlers> </system.web> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="3000000000" /> </requestFiltering> </security> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" /> <directoryBrowse enabled="true" /> <handlers> <remove name="asset" /> <add name="asset" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler,Telerik.Web.Mvc" /> </handlers> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.WindowsAzure.StorageClient" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.7.0.0" newVersion="1.7.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 解决方法
与cookieless =“true”一起使用时,Html.BeginForm()助手(不带任何参数的助手)中存在错误.它在生成URL时不考虑会话ID.所以代替:
<form action="/(S(kkt0zgbnuaoxad23ew33iod4))/home/index" method="post"> 它产生: <form action="/home/index" method="post"> 当您发布到/ home / index时,ASP.NET会自动对/(S(kkt0zgbnuaoxad23ew33iod4))进行重定向.重定向意味着GET请求=>你的POST动作永远不会被击中. 作为一种解决方法,您可以编写自定义的Html.BeginForm帮助程序来修复该错误: public static class FormExtensions { public static IDisposable MyBeginForm(this HtmlHelper htmlHelper) { var rawUrl = htmlHelper.ViewContext.HttpContext.Request.RawUrl; var formAction = htmlHelper.ViewContext.HttpContext.Response.ApplyAppPathModifier("~/") + rawUrl; var builder = new TagBuilder("form"); builder.MergeAttributes(new RouteValueDictionary()); builder.MergeAttribute("action",formAction); builder.MergeAttribute("method",HtmlHelper.GetFormMethodString(FormMethod.Post),true); htmlHelper.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag)); var form = new MvcForm(htmlHelper.ViewContext); return form; } } 然后使用: @using (Html.MyBeginForm()) { ... } 就BeginForm帮助器的其他重载而言,它们应该正常工作并生成包含会话ID的适当操作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ModelState.AddModelError – 未显示错误
- asp.net – 最后修改标头在MVC
- asp.net – GET与POST真的很重要吗?
- asp.net-mvc – ASP.NET中的Dapper,ODATA和IQueryable
- asp.net-mvc – ASP.NET MVC Html.DropDownList由Ajax调用控
- asp.net-mvc – 如何在MVC5中从AccountController模拟Appli
- asp.net – Sitecore – System.Security.Cryptography.Cry
- asp.net – 更改ContentPlaceHolder的ID
- asp.net – 从umbraco搜索中排除节点
- asp.net-mvc – Asp.Net MVC2 RenderAction更改页面mime类型
推荐文章
站长推荐
- asp.net-mvc – Robots.txt,禁止多语言URL
- .net core 3.0_webapi项目使用Swagger提供接口帮
- ASP.NET MVC 3中的c# – @ Html.ActionLink
- 事件(Event),绝大多数内存泄漏(Memory Leak)的
- 在ASP.net页面中嵌入SVG
- asp.net-mvc – 自定义HtmlHelper呈现文本而不是
- ASP.NET MVC3 AJAX.BeginForm AjaxOptions OnSuc
- asp.net – 带超时异常的reCaptcha验证
- .net-core – VS 2017中缺少ASP.NET Core 2模板
- asp.net-mvc-2 – 使用web.config文件在ASP.NET
热点阅读